【TeeChart for Java教程】(四)下——轴控制:附加轴

【下载TeeChart for Java最新版本】

(一)附加轴

1.1 复制轴

TeeChart提供5个与数据系列相关的轴:Left、Top、Bottom、Right和Depth。将新系列添加到图表时,您可以定义系列应与哪些轴相关(转到“Series”选项卡,“General ”页面),您可以使用Axis Customdraw方法在图表上的任何位置重复4个前轴中的任何一个(或全部)。请注意,此方法会复制Axis,但不会添加新的自定义轴。

//fill the Series for this example with random dataprocedure TForm1.BitBtn1Click(Sender: TObject);Var t:integer;begin  For t := 0 To 20 do    Series1.AddXY(t, Random(100) - Random(70), '', clRed);end;//Put this code in the OnBeforeDrawValues() event:procedure TForm1.Series1BeforeDrawValues(Sender: TObject);var posaxis :Integer;begin  With Chart1 do  begin    If LeftAxis.Maximum > 0 Then    begin      //When scrolling or on zoom always keep the gridlines enclosed in the Chart rectangle      Canvas.ClipRectangle(ChartRect);      //Always draw the 2nd vertical Axis at the middle point of the Chart      posaxis := (ChartRect.Left) + (ChartRect.Right - ChartRect.Left) div 2;      LeftAxis.CustomDraw(posaxis - 10, posaxis - 20, posaxis, True);      //Draw the 2nd Horizontal axis at the level of "10" on the vertical axis      posaxis := (LeftAxis.CalcYPosValue(10));      BottomAxis.CustomDraw(posaxis + 10, posaxis + 40, posaxis, True);      Canvas.UnClipRectangle;    end;  end;end;

teechart_for_java

在此示例中,TeeChart将绘制新轴,一个水平,一个垂直位于图表的中心。当您滚动图表(用鼠标右键拖动)时,新的垂直轴将始终保持在图表的中心,新的水平轴将垂直滚动上下移动,新轴是默认轴的精确副本。

1.2 多个自定义轴(仅限专业版)

1.2.2 通过代码
Line line1 = new Line();Line line2 = new Line();  tChart2.getAspect().setView3D(false);  tChart2.getPanel().getGradient().setVisible(true);  tChart2.getHeader().setText("TeeChart Multiple Axes");  tChart2.getSeries(0).add(line1);  tChart2.getSeries(1).add(line2);    for(int t = 0; t <= 10; ++t) {      line1.add(t, (10 + t), Color.Red);      if(t > 1) {        line2.add(t, t, Color.Green);    }}  tChart2.getAxes().getLeft().setStartPosition(0);  tChart2.getAxes().getLeft().setEndPosition(50);  tChart2.getAxes().getLeft().getAxisPen().color = Color.Red;  tChart2.getAxes().getLeft().getTitle().getFont().setColor(Color.Red);  tChart2.getAxes().getLeft().getTitle().getFont().setBold(true);  tChart2.getAxes().getLeft().getTitle().setText("1st Left Axis");

然后,您可以使用StartPosition和EndPosition方法将新轴与图表的整体关系定位,这些数字表示为图表矩形的百分比,其中0(零)(在 垂直轴的情况下)为Top。这些属性可以应用于标准轴,以在图表中创建完全分区的“SubCharts”。

Axis axis1 = new Axis(false, false, tChart2.getChart());  tChart2.getAxes().getCustom().add(axis1);  line2.setCustomVertAxis(axis1);    axis1.setStartPosition(50);    axis1.setEndPosition(100);    axis1.getAxisPen().setColor(Color.Green);    axis1.getTitle().getFont().setColor(Color.Green);    axis1.getTitle().getFont().setBold(true);    axis1.getTitle().setText("Extra Axis");    axis1.setRelativePosition(20);    }}

上面的编码示例将显示以下图表:

teechart_for_java

标签:图表Javateechart

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年8月3日
下一篇 2018年8月3日

相关推荐

发表回复

登录后才能评论