将JFreeChart系列名称映射到系列索引 [英] Mapping JFreeChart Series Name to Series Index
问题描述
我正在使用 StackedXYBarRenderer
绘制 TimeTableXYDataset
。不幸的是,每个系列的颜色在刷新时都会发生变化。
I'm plotting a TimeTableXYDataset
using a StackedXYBarRenderer
. Unfortunately the colours of each series change on refresh.
我知道如何使用 setSeriesPaint
方法设置颜色渲染器,但它以整数系列索引作为参数。我使用字符串作为系列名称创建数据点:
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()));
如何发现系列名称和系列索引之间的映射,以便我可以调用 setSeriesPaint
?
How do I discover the mapping between series name and series index so I can call setSeriesPaint
?
推荐答案
最简单的方法是更新合适的地图
随着数据的累积。或者,方法 getSeriesKey()
和 indexOf()
可用于向任一方向转换。例如,
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);
}
这篇关于将JFreeChart系列名称映射到系列索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!