【下载TeeChart for Java最新版本】
(一)轴控制——关键领域
1.1 Scales
将Series数据添加到图表时,会自动设置轴刻度,可以在设计时通过代码或在运行时使用Axis方法更改默认值。

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

如果您的数据是datetime(您可以通过转到Series,General页面将数据设置为系列的日期时间,如此图所示),图表,轴页面和比例部分将显示日期时间范围,从所需增量组合框中显示的范围中进行选择,添加一些示例数据:
tChart1.getAxes().getBottom().setIncrement(Utils.getDateTimeStep(DateTimeStep.ONEDAY));tChart1.getAxes().getBottom().getLabels().setDateTimeFormat("ddMMM 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
tChart1.getAxes().getBottom().getLabels().setValueFormat("#,##0.00;(#,##0.00)");//or for Datetime datatChart1.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 styletChart1.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

有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);
标签:图表Java图表库图表解决方案图表控件teechart
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!