【问题标题】:JfreeChart Axis custom precision or rangeJfreeChart Axis 自定义精度或范围
【发布时间】:2014-04-30 05:43:19
【问题描述】:

我正在尝试使用 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 谢谢

【问题讨论】:

    标签: jfreechart


    【解决方案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));
    

    【讨论】:

    • 这能回答你的问题吗?在这种情况下,请将您的问题标记为已解决。谢谢!
    猜你喜欢
    • 2012-08-07
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多