问题描述
我有一个 JFree XY 折线图,它总是从 x = 0 开始.然后根据用户定义的属性文件设置,应用程序根据该数字递增(这表示以分钟为单位的时间).
例如,x = 0 开始用户定义的设置为 5,因此比例变为 0, 5, 10, 15, 20...,或者用户设置为 3,因此变为 0, 3, 6, 9, 12... 很简单.
我遇到的问题是图表开始的方式.如果我从 0 开始,那么 0 位于图表的中间而不是左下角 -0.0000005, -0.000004, -0.000003... 0.000000 , 0.000001 , 0.000002... 0.000005
我怎样才能在底部手动添加比例,即定义它应该是 2 的增量然后保持它?你应该使用 NumberAxis
,其中包含许多定义图表比例的方法.
示例:
//创建 XY 折线图XYSeries 系列 = new XYSeries("随机数据");系列.add(1.0, 500.2);系列.add(10.0, 694.1);XYSeriesCollection 数据 = 新的 XYSeriesCollection(series);JFreeChart 图表 = ChartFactory.createXYLineChart("XY 系列演示", "X", "Y", data,PlotOrientation.VERTICAL,真、真、假);//创建一个数字轴NumberAxis xAxis = new NumberAxis();xAxis.setTickUnit(new NumberTickUnit(2));//将其分配给图表XYPlot plot = (XYPlot) chart.getPlot();plot.setDomainAxis(xAxis);
I have a JFree XY Line chart which always starts at x = 0. Then based on user defined settings from a properties file, the application increments based on that number (this represents the time in minutes).
For example, x = 0 to start the user defined setting is 5 so the scale goes 0, 5, 10, 15, 20…, or the user setting is 3 so it goes 0, 3, 6, 9, 12… Pretty simple.
The issue I am having is the way in which the graph starts. If I start at 0, then 0 is in the middle of the graph rather than at the bottom left with -0.0000005, -0.000004, -0.000003… 0.000000 , 0.000001 , 0.000002… 0.000005
How can I just manually add the scale at the bottom, i.e. define it should be increments of 2 and then maintain it?
You should use NumberAxis
, which contains a lot of methods to define the scale of your chart.
Example :
// Create an XY Line chart
XYSeries series = new XYSeries("Random Data");
series.add(1.0, 500.2);
series.add(10.0, 694.1);
XYSeriesCollection data = new XYSeriesCollection(series);
JFreeChart chart = ChartFactory.createXYLineChart("XY Series Demo", "X", "Y", data,
PlotOrientation.VERTICAL,
true, true, false);
// Create an NumberAxis
NumberAxis xAxis = new NumberAxis();
xAxis.setTickUnit(new NumberTickUnit(2));
// Assign it to the chart
XYPlot plot = (XYPlot) chart.getPlot();
plot.setDomainAxis(xAxis);
这篇关于JFreeChart x 轴刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!