JFReeChart x轴缩放 [英] JFReeChart x axis scale

查看:257
本文介绍了JFReeChart x轴缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个始终从x = 0开始的JFree XY线图。然后根据属性文件中的用户定义设置,应用程序基于该数字递增(这代表以分钟为单位的时间)。

例如,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 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);

//创建一个NumberAxis
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, ie define it should be incrememnts of 2 and then it maintains it?

Thanks for your time

解决方案

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轴缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆