Display JFreeChart Series Name for Series Index

I draw TimeTableXYDatasetwith StackedXYBarRenderer. Unfortunately, the colors of each series change when updated.

I know how to set colors using the setSeriesPaintrenderer method , but takes an integer index as an argument. I create my datapoints using a string as the name of the series:

ds.add(new SimpleTimePeriod(us.getDate(), 
                            new Date(us.getDate().getTime() + 1000*60)),
       us.getTotal(), us.getName()));

How do I know the mapping between a series name and a series index so that I can call setSeriesPaint?

+5
source share
1 answer

- Map . , getSeriesKey() indexOf() . ,

for (int i = 0; i < ds.getSeriesCount(); i++) {
    String name = (String) ds.getSeriesKey(i);
    System.out.println(ds.indexOf(name) + ": " + name);
}
+3

All Articles