【TeeChart for Java教程】(四)上——轴控制:关键领域

【下载TeeChart for Java最新版本】

(一)轴控制——关键领域

1.1 Scales

将Series数据添加到图表时,会自动设置轴刻度,可以在设计时通过代码或在运行时使用Axis方法更改默认值。

teechart_for_java

添加新系列时,图表编辑器的“Axis”页面的“Scales”部分将显示已选中“Visible”和“Automatic”,并且未选中“Inverted”。在编辑器的底部有两个选项卡,Maximum和Minimum。在此处,您可以设置“ Offset”值,以在取消选中“Auto”时沿选定轴移动图表。

Automatic选择最佳轴刻度范围以适合您的数据,如果关闭“Automatic”,“Scales”部分将激活选项,您可以更改“Axis”值,从页面左侧的“Axis”列表中选择要配置的轴,将行系列添加到图表中添加一个命令按钮,其中包含以下代码:

tChart1.removeAllSeries();
tChart1.addSeries(new Line()).fillSampleValues(40);

在按钮中运行代码将绘制一个包含40个随机值的Line Series,现在可以配置轴刻度的最大值和最小值。

tChart1.getAxes().getBottom().setAutomatic(false);
tChart1.getAxes().getBottom().setMaximum(36);
tChart1.getAxes().getBottom().setMinimum(5);

再次运行代码将显示值,具体取决于为Axis配置的值,使用鼠标右键可以滚动查看剩余值。可以将Axis scale Maximum和Minimum设置为自动单独,例如:

tChart1.getAxes().getBottom().setAutomaticMaximum(true);
tChart1.getAxes().getBottom().setMinimum(5);

1.2 Increment

可以定制Axis的间隔,从Axis页面的Scales部分选择Desired Increment组合框,并添加所需的增量,可以在运行时通过代码更改它:

tChart1.getAxes().getBottom().setIncrement(20);

1.2.1 Datetime data

teechart_for_java

如果您的数据是datetime(您可以通过转到Series,General页面将数据设置为系列的日期时间,如此图所示),图表,轴页面和比例部分将显示日期时间范围,从所需增量组合框中显示的范围中进行选择,添加一些示例数据:

tChart1.getAxes().getBottom().setIncrement(Utils.getDateTimeStep(DateTimeStep.ONEDAY));
tChart1.getAxes().getBottom().getLabels().setDateTimeFormat("dd
MMM yyyy");

DateTime d = DateTime.getNow(); d.add(5,1);
tChart2.getSeries(0).add(d, 20); d.add(5,1);
tChart2.getSeries(0).add(d, 30); d.add(5,1);
tChart2.getSeries(0).add(d, 40); d.add(5,1);
tChart2.getSeries(0).add(d, 35);

在运行时更改增量:

tChart2.getAxes().getBottom().setIncrement(com.steema.teechart.DateTimeStep.ONEWEEK);

1.3 titles

titles在Axis页面的titles部分中设置,您可以更改Axis及其字体的标题文本,该角度可以从值0,90,180,270度中选择。

1.4 Labels

1.4.1 Note

更改轴标签频率时,请记住TeeChart将根据LabelsSeparation方法的设置避免标签重叠。这意味着如果标签频率太高而不适合标签,那么TeeChart将分配“best fit”。更改标签角度和标签分离是2个选项,可帮助您安装所需的标签。

1.4.2 Label formats

您可以将所有标准数字和日期格式应用于Axis标签,“Axis”页面的“Labels”部分包含“Values format”字段,如果您的数据是datetime,则字段名称将更改为“Date time format”。在编辑器中拖动帮助“?” 在该字段上的图标,以获得完整的选项列表,在运行时使用:

tChart1.getAxes().getBottom().getLabels().setValueFormat("#,##0.00;(#,##0.00)");

//or for Datetime data

tChart1.getAxes().getBottom().getLabels().setDateTimeFormat("dddd/mmmm/yyyy");

1.4.3 MultiLine labels

轴标签可以显示为多行文本而不是单行文本,使用TeeLineSeparator全局常量分隔行,该常量默认为回车符ascii字符(#13)。

//Add the Series labels in this way and apply 'Marks' as Axis labelling style
tChart1.getSeries(0).add(1234, "New"+com.steema.teechart.Texts.LineSeparator+" cars", Color.Blue );
tChart1.getSeries(0).add(2000, "Old"+com.steema.teechart.Texts.LineSeparator+" bicycles", Color.Green);
tChart1.getPanel().setMarginBottom(10);

DateTime标签的示例:

1.5 Ticks

teechart_for_java

有3种刻度类型,您可以更改每种刻度类型的长度,宽度和颜色。如果刻度线宽度设置为1(默认值),则可以将样式更改为多种线型之一(点,短划线等),如果width大于1,则将忽略样式。

tChart1.getAxes().getBottom().getTicks().setLength(7);
tChart1.getAxes().getBottom().getTicks().setColor(Color.GREEN);
tChart1.getAxes().getBottom().setMinorTickCount(10);

1.6 Axis position

轴有一种方法可以修改每个轴的位置,在此示例中,轴移动到图表总宽度的50%,因此它显示在图表中心:

tChart1.getAxes().getLeft().setRelativePosition(50);

转载于:https://my.oschina.net/u/3942001/blog/1942244

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值