使用 jfreechart 在不同点之间创建 XY 图表

creating XY Chart between different points with jfreechart

我正在尝试使用 jfreechart 在 XY 图表中的多个点之间创建互连。这个 chart.add( 1.0 , 4.0 );chart.add( 2.0 , 5.0 ); chart.add( 2.5 , 7.0 ); 有点把它们连接成一条线。像这样 - wrong image. But I want to return back to the 1st point and create a chart like this -correct image。我想对多个基本节点重复它。像这样 -

for(int i=0;i<=1000;i++){
  for(int j=0;j<=30;j++){
    chart.add(arr1[i], arr2[j]);
  }
}

我该怎么做?

尝试使用多个 XYSeries:

在 XYSeries 构造函数中,将 autosort 设置为 false 以允许线条在需要时向后移动,如果您可能需要通过已绘制的点导航系列,则将 allowDuplicates 设置为 true。

    final XYSeries series1 = new XYSeries("Data 1", false, true);
    series1.add( 1.0 , 4.0 );
    series1.add( 2.0 , 5.0 );

    final XYSeries series2 = new XYSeries("Data 2", false, true);
    series2.add( 1.0 , 4.0 );
    series2.add( 2.5 , 7.0 );

    final XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series1);
    data.addSeries(series2);

    final JFreeChart chart = ChartFactory.createXYLineChart(
            "XY Chart",
            "X",
            "Y",
            data,
            PlotOrientation.VERTICAL,
            true,
            true,
            false
    );

要添加更多数据系列,请多次调用 XYSeriesCollection.addSeries(series)。