2

Is there any way to make a lot of new series for JFreeChart by using a for loop? I tried something like this. I know that does't work; but if you tell me some other way or maybe fix my code, I would appreciate it.

for(int i=0;i<10;i=i){

    String series[]=new String[10];
    String dataset[]=new String[10];
                    series[i]="series"+i;
                    dataset[i]="dataset"+i;

    final XYSeries series[i] = new XYSeries("XYGraph");

    XYSeriesCollection dataset[i] = new XYSeriesCollection();
    dataset[i].addSeries(series[i]);
    chart.getXYPlot().setDataset(i-1,dataset[i]);

    series[i].add(i,2); 
    series[i].add(i,-2);        

     i=i+1;
     }
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045

1 Answers1

2

Starting form this example, I added a for loop to create the following variation. The critical issue is identifying the correct parameters to pass to createSeries(). This example—having only a String and an int— is intentionally simple to show the outline.

private XYDataset createDataset() {
    TimeSeriesCollection tsc = new TimeSeriesCollection();
    for (int i = 1; i < 6; i++) {
        tsc.addSeries(createSeries("Series " + String.valueOf(i), i * 100));
    }
    return tsc;
}

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045