我想使用jfreechart这是我的代码来创建图像文件:

 XYSeries xydata = new XYSeries("fitness");
    for (int i = 0; i < it; i++) {
        xydata.add(i,fitness[i]);
        //System.out.println(fitness[i]);
    }

    XYSeriesCollection fitness_series = new XYSeriesCollection();
    fitness_series.addSeries(xydata);

    //Use createXYLineChart to create the chart
    JFreeChart XYLineChart = ChartFactory.createXYLineChart("fitness", "iteration", "fitness", fitness_series, PlotOrientation.VERTICAL, true, true, false);

    /* Step -3 : Write line chart to a file */
    int width = 640; /* Width of the image */
    int height = 480; /* Height of the image */
    File XYlineChart = new File("xy_line_Chart_fitness.png");
    ChartUtilities.saveChartAsPNG(XYlineChart, XYLineChart, width, height);


结果是:


但是y轴从我设置的第一个值开始,而不是如上图所示的0,我如何将其设置为自己的特定值?还是我拥有的最低x数据?

最佳答案

默认情况下,NumberAxis类将根据您的实际数据值计算其范围,并且默认情况下包括零。您可以设置一个标志来控制是否包含零:

http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/NumberAxis.html#setAutoRangeIncludesZero-boolean-

07-28 04:40