【TeeChart for Java教程】(十一)打印图表

【下载TeeChart for Java最新版本】

(一)标准打印

TeeChart Pro提供标准打印方法,可将“屏幕图表”按原样打印到打印机。

1.1 简单打印命令

要打印图表,请使用Print方法。这将打印出屏幕上显示的图表,例:

tChart1.getPrinter().print();

1.2 打印方向

Print方法允许您通过使用布尔横向参数来打印横向和纵向方向,即使它们未被定义为默认方向。打印完成后,默认方向将再次生效。可以使用Landscape属性更改默认方向(对于Landscape,设置为true,对于Portrait,设置为false),例:

tChart1.getPrinter().setLandscape(true);
tChart1.getPrinter().print();

1.3 打印预览

PrintPreview窗口将显示图表在打印时的显示方式。您可以在“Print Preview”窗口中修改打印参数。要调用PrintPreview运行:

tChart1.getPrinter().preview(); 

1.4 灰度打印

打印到Greyscale打印机时,您应该注意,当转换为灰色阴影时,图表的颜色很容易区分。为了提供帮助,您可以在图表系列中添加画笔样式,以便在打印时更轻松地区分系列。您还可以使用灰度属性将彩色图表打印到彩色打印机:

tChart1.getPrinter().setGrayscale(true);
tChart1.getPrinter().print(true);

(二)扩展打印方法

2.1 打印多个图表

使用beginPrint()和endPrint()将图表发送到打印机而不弹出页面; BeginPrint()和EndPrint()开始和结束打印机作业。可以将多个图表发送到同一页面/打印机作业,也可以包含用户自定义输入。示例(将2个图表打印到页面):

public void button1_actionPerformed(ActionEvent e) {

        tChart1.getPrinter().beginPrint();
        tChart1.getPrinter().print(tChart2.getChart().chart,new com.steema.teechart.Rectangle(100,10,300,200)); 
        tChart1.getPrinter().print(new com.steema.teechart.Rectangle(100,300,300,200));        
        tChart1.getPrinter().endPrint(); 
}

2.2 在一页上打印预览多个图表

打印预览器现在接受多个图表。控制图表位置设置Print方法的Rectangle,示例(在打印预览器中显示2个图表):

public void button1_actionPerformed(ActionEvent e) {

        tChart1.getPrinter().beginPrint();
        tChart1.getPrinter().print(tChart2.getChart().chart,new com.steema.teechart.Rectangle(100,10,300,200)); 
        tChart1.getPrinter().print(new com.steema.teechart.Rectangle(100,300,300,200));        
        tChart1.getPrinter().preview(); 
}

2.3 将打印的图表输出与其他打印输出混合

使用ChartPrint()事件将TeeChart打印输出与非Chart打印机输出混合。以下示例从TeeChart标题中获取文本,并在具有两个TChart对象的页面上打印它们:

public void button1_actionPerformed(ActionEvent e) {

        tChart1.getPrinter().beginPrint();
        tChart1.getPrinter().print(tChart2.getChart().chart,new com.steema.teechart.Rectangle(100,10,300,200)); 
        tChart1.getPrinter().print(new com.steema.teechart.Rectangle(100,300,300,200));        
        tChart1.getPrinter().endPrint(); 
}

    public void doChartPrint(Object sender, PrintPageEventArgs e) {        
        e.drawString("Chart: "+((com.steema.teechart.printer.ChartPrintJob)sender).getChart().getHeader().getText(), 
                     100,((com.steema.teechart.printer.ChartPrintJob)sender).getChart().getChartRect().getBottom()+10); 
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值