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

本文详细介绍了在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);    }

购买TeeChart for Java正版授权,请点击“咨询在线客服”哟!

FastReport2018.4

标签:图表Java图表库图表解决方案图表控件teechart

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年8月22日
下一篇 2018年8月23日

相关推荐

发表回复

登录后才能评论