为时间序列分配油漆

Getting Assigned Paint for TimeSeries

我显然不理解 getSeriesPaint 方法的文档。我有 TimeSeries 对象,我想获取用于渲染它的颜色。但是,我好像陷入了第 22 条军规。我需要知道系列索引(getIndex),但是要找到我需要知道系列时间段。但是,要找到系列时间段,我需要知道索引。我想做这样的事情:

Color color=(Color) r1.getSeriesPaint(arg0);

其中 r1XYLineAndShapeRenderer。给定 TimeSeries 对象,我对 arg0 使用什么?

因为XYLineAndShapeRenderer is an XYItemRenderer, it invokes the AbstractRenderer method getItemPaint(), which "Returns the paint used to color data items as they are drawn." Note that "The default implementation passes control to the lookupSeriesPaint() method." Starting from this example,以下片段从图表中获取数据集和渲染器。然后它列举系列颜料——图像中看到的红色和蓝色阴影:

JFreeChart chart = chartPanel.getChart();
XYPlot plot = (XYPlot) chart.getPlot();
TimeSeriesCollection tsc = (TimeSeriesCollection) plot.getDataset();
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
for (int i = 0; i < tsc.getSeriesCount(); i++) {
    System.out.println(renderer.lookupSeriesPaint(i));
}

控制台:

java.awt.Color[r=255,g=85,b=85]
java.awt.Color[r=85,g=85,b=255]

或者,考虑自定义 DrawingSupplier,提到 here