3

我设法绘制了一个线性图。以下是代码:

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

但是,它不是平滑的曲线,而是直线。请问我怎样才能使它顺利?

4

1 回答 1

5

相信你在找XYSplineRenderer 你应该可以做到

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

构建图表后。

于 2012-12-05T16:23:15.627 回答