JFreeChart x axis scale

前端 未结 2 1339
北荒
北荒 2021-01-01 23:27

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

2条回答
  •  死守一世寂寞
    2021-01-01 23:53

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

提交回复
热议问题