JfreeChart Axis定制精度或范围

时间:2014-04-30 05:43:20

标签: jfreechart

我正在尝试使用JfreeChart绘制XYPlot。我的X轴有数字或客户说30,50,70 和Y轴有缓存命中率(有时值变化为0.01)当我设置AutoRange时,y轴显示范围为0.1 0.2 0.3 ..... 1.0。所以有时我的情节几乎是直线,因为它因这么小的因素而变化。

我试过这段代码

             JFreeChart chart = ChartFactory.createXYLineChart(
             "Effect of Number of Clients", // Title
             "Number of Clients", // x-axis Label
             "Cache Hit Ratio", // y-axis Label
             datasetLRU, // Dataset
             PlotOrientation.VERTICAL, // Plot Orientation
             true, // Show Legend
             true, // Use tooltips
             false // Configure chart to generate URLs?
             );
             chart.setBackgroundPaint(Color.white);
             plot= chart.getXYPlot();
             plot.setBackgroundPaint(Color.black);
             plot.setDomainGridlinePaint(Color.white);
             plot.setRangeGridlinePaint(Color.white);

             final ValueAxis axis = plot.getDomainAxis();
             axis.setAutoRange(false);

             final NumberAxis axis2 = new NumberAxis("Axis 2");
             axis2.setAutoRangeIncludesZero(false);
             axis2.setTickUnit(new NumberTickUnit(0.01));

             plot.setDataset(1, datasetMARS);
             plot.setRenderer(1, new StandardXYItemRenderer());
             plot.setDataset(2, datasetNEW);
             plot.setRenderer(2, new StandardXYItemRenderer());

因此任何人都可以帮助将Y轴范围设置为0.01 0.02 0.03 .... 0.98 0.99 1.00 谢谢

1 个答案:

答案 0 :(得分:1)

您的代码没有配置范围轴,因为您创建了axis2,但您从未分配它。使用自动量程时,您还可以配置自动量程轴的最小值(方法setAutoRangeMinimumSize(double))。

请尝试以下源代码部分:

final NumberAxis axis2 = plot.getRangeAxis();
axis2.setAutoRange(true);
axis2.setAutoRangeIncludesZero(false);
axis2.setAutoRangeMinimumSize(0.001);
axis2.setTickUnit(new NumberTickUnit(0.01));