How to make plot a curve using JFreeChart?

坚强是说给别人听的谎言 提交于 2019-12-18 07:06:22

问题


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?


回答1:


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

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

after your chart is constructed.



来源:https://stackoverflow.com/questions/13727474/how-to-make-plot-a-curve-using-jfreechart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!