jajamaharaja
jajamaharaja

Reputation: 135

jfree chart set show range x value in chart

I want to create a image file using jfreechart heres my code :

 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);

and the result is : result

but the y axis start with the first value of my set not a 0 like in the picture shown above, how do i set it to my own specific value ? or the lowest x data that i have ?

Upvotes: 0

Views: 635

Answers (1)

David Gilbert
David Gilbert

Reputation: 4477

The NumberAxis class will, by default, calculate its range from your actual data values as well as including zero by default. There is a flag that you can set to control whether or not zero is included:

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

Upvotes: 1

Related Questions