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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.