series.add不添加新系列

时间:2022-04-20 13:28:26

I've modified XYseries demo for charting with Android using AChartEngine. It doesn't add the second array as a new series. Here is my code.

我使用AChartEngine修改了XYseries演示,用于Android图表。它不会将第二个数组添加为新系列。这是我的代码。

 private XYMultipleSeriesDataset getDemoDataset() {
     XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    final int nr = 10;


    double[] test1=new double[] {121.0,122.0,123.0,124.0,125.0,126.0,127.0,128.0,129.0,130.0};
    double[] test2=new double[] {131.0,132.0,133.0,134.0,135.0,136.0,137.0,138.0,139.0,140.0};

    double[] testArray= new double[test1.length + test2.length];
    System.arraycopy(test1, 0, testArray, 0, test1.length);
    System.arraycopy(test2, 0, testArray, test1.length, test2.length);

    for(double d:testArray){
    Log.i(MAIN_DEBUG_TAG, "testArray "+d);
    }

      Random r = new Random();
      for (int i = 0; i < SERIES_NR; i++) {
      XYSeries series = new XYSeries("Demo series " + (i + 1));
      for (int k = 0; k < nr; k++) {

     // series.add(k, 120 + r.nextInt() % 100);
    series.add(k, testArray[k]);

    Log.i(MAIN_DEBUG_TAG, "series.add  "+k +"   "+test1[k]);

     }
    dataset.addSeries(series);        
    }         

        return dataset;
  }

Test1 array is repeated. If I remove the comments from series.add(k,120+ random...... it will genereated 2 series of data to plot. Any help appreciated. TIA

重复Test1数组。如果我从series.add删除评论(k,120 +随机......它将生成2个系列的数据来绘制。任何帮助表示感谢.TIA

1 个解决方案

#1


0  

You're adding the same data points twice - testArray[0] to testArray[9] in both iterations of the outer loop. k always goes from 0 to 9, and the current code doesn't rely on anything other than k:

您在外部循环的两次迭代中将两次相同的数据点 - testArray [0]添加到testArray [9]。 k总是从0到9,当前代码不依赖于k以外的任何东西:

// No sign of anything that changes between iterations of the outer loop
series.add(k, testArray[k]);

How about:

 series.add(k, testArray[k + i * nr]);

That way the first series will have testArray[0] to testArray[9], and the second series will have testArray[10] to testArray[19].

这样第一个系列将testArray [0]传递给testArray [9],第二个系列将testArray [10]传递给testArray [19]。

#1


0  

You're adding the same data points twice - testArray[0] to testArray[9] in both iterations of the outer loop. k always goes from 0 to 9, and the current code doesn't rely on anything other than k:

您在外部循环的两次迭代中将两次相同的数据点 - testArray [0]添加到testArray [9]。 k总是从0到9,当前代码不依赖于k以外的任何东西:

// No sign of anything that changes between iterations of the outer loop
series.add(k, testArray[k]);

How about:

 series.add(k, testArray[k + i * nr]);

That way the first series will have testArray[0] to testArray[9], and the second series will have testArray[10] to testArray[19].

这样第一个系列将testArray [0]传递给testArray [9],第二个系列将testArray [10]传递给testArray [19]。