3

I have managed to plot a linear graph. The following is the code:

private JPanel createGraph() {

        JPanel panel = new JPanel();
        XYSeries series = new XYSeries("MyGraph");
        series.add(0, 1);
        series.add(1, 2);
        series.add(2, 5);
        series.add(7, 8);
        series.add(9, 10);


        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(series);

        JFreeChart chart = ChartFactory.createXYLineChart(
                "XY Chart",
                "x-axis",
                "y-axis",
                dataset, 
                PlotOrientation.VERTICAL,
                true,
                true,
                false
                );
        ChartPanel chartPanel = new ChartPanel(chart);


        panel.add(chartPanel);

        return panel;
    }

However, it is not a smooth curve, but straight lines. How can I make it smooth please?

2
  • Without seeing the graph itself I think is because is how it is supposed to be. If you want a curve you should add more points to the graph that eventually forms a curve. Commented Dec 5, 2012 at 16:14
  • My graph is something similar to this: java2s.com/Code/Java/Chart/JFreeChartXYSeriesDemo.htm Commented Dec 5, 2012 at 16:18

1 Answer 1

6

I believe that you are looking for XYSplineRenderer You should be able to do

chart.getXYPlot().setRenderer(new XYSplineRenderer());

after your chart is constructed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.