how to know color of lines in TimeSeriesChart?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
fruit112358
Posts: 3
Joined: Fri Apr 08, 2011 4:45 pm
antibot: No, of course not.

how to know color of lines in TimeSeriesChart?

Post by fruit112358 » Fri Apr 08, 2011 5:02 pm

Hello,

How can I know the color of every line in a time series chart?

I know how to set the color by setSeriesPaint(), but I do not know how to get default color of all lines in time series chart without custom setting.

Any idea?

Jie

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: how to know color of lines in TimeSeriesChart?

Post by paradoxoff » Sat Apr 09, 2011 9:04 am

If a renderer renders a data item of a series, and the paint for the series has not yet been specified, the renderer will ask a "drawing supplier" for the next paint (check AbstractRenderer.lookupSeriesPaint(int series) which is calling the abstract method getDrawingSupplier()). A renderer extending AbstractXYItemRenderer will return the DrawingSupplier of the XYPlot (see AbstractXYItemRenderer.getDrawingSupplier()) . By default, an XYPlot uses an instance of DefaultDrawingSupplier.
A DefaultDrawingSupplier will simply iterate over a list of predefined colors. You can check what colors are being used by looking at the source of DefaultDrawingSupplier.
If you need to control that behaviour, and if you do not want to set all colors explicitly, you can use an instance of DefaultDrawingSupplier and define the colors, shapes, strokes etc. in the constructor, or you can implement that interface on your own. In any case, call XYPlot.setDrawingSupplier(DrawingSupplier yourSupplier) before you draw the chart.

fruit112358
Posts: 3
Joined: Fri Apr 08, 2011 4:45 pm
antibot: No, of course not.

Re: how to know color of lines in TimeSeriesChart?

Post by fruit112358 » Mon Apr 11, 2011 3:20 pm

Thank you very much and the problem is solved:)

However, I found another interesting place. When I set legend of a chart to be visible, the sequence of lines' color is inverted compared with chart with invisible legend.

For example, for the same dataset with three series, their colors are red, blue and green when legend is not visible. However, when legend is visible, order of colors is changed to green, blue and red.

Although this do not effect my application, I still want to know the reason, does anyone have idea?

Jie

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: how to know color of lines in TimeSeriesChart?

Post by paradoxoff » Tue Apr 12, 2011 8:25 pm

Does is go away when you call

Code: Select all

xyplot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

aherz
Posts: 1
Joined: Fri Dec 18, 2015 2:50 pm
antibot: No, of course not.

Re: how to know color of lines in TimeSeriesChart?

Post by aherz » Fri Dec 18, 2015 2:54 pm

Hi,

I happened to run into the same problem.
Calling
xyplot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD)

indeed fixed the problem of inverted color order (when drawing either with or without legend). Although, I would have expected that as default behavior (always same order unless explicitly specified otherwise).

Regards,
Alex

Locked