Mapping JFreeChart Series Name to Series Index

徘徊边缘 提交于 2019-12-10 04:23:00

问题


I'm plotting a TimeTableXYDataset using a StackedXYBarRenderer. Unfortunately the colours of each series change on refresh.

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

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

How do I discover the mapping between series name and series index so I can call setSeriesPaint?


回答1:


The easiest approach is to update a suitable Map as the data accumulates. Alternatively, the methods getSeriesKey() and indexOf() may be used to convert in either direction. For example,

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


来源:https://stackoverflow.com/questions/3082863/mapping-jfreechart-series-name-to-series-index

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!