Random Color Picker

Oystein Bjorke 6 years ago 0
This discussion was imported from CodePlex

jpnavarini wrote at 2012-03-19 17:44:

I would like to create a trend with multiple LineSeries, however it would be necessary to pick a different color for each added LineSeries. Is there a color picker function to choose "random" colors, or I would have to do it manually?

objo wrote at 2012-03-20 18:26:

See the DefaultColor property of the PlotModel, you can change this to a list of random colors. The default value uses a predefined palette, not random colors. 

ps. I will change the DefaultColor property to an IList<Color>

jpnavarini wrote at 2012-03-20 18:50:

When I add a new LineSeries to the Series list, it plots using the same default color (dark green). However, when I add multiple plots at once (inside the same loop, for example), each lineseries get a different color. That color rotation is what I wanted, however with lineseries added at different moments.

objo wrote at 2012-03-30 13:20:

Sorry, I don't quite understand. Is this a bug in the library? Do you add all series to the same plot?

I would like the plot always to generate the same colors (no randomness), if you want random colors to be generated when adding new series, this should be handled by your code.

JeanBisson wrote at 2014-01-09 17:27:

I believe I have a good handle with regard to random colors being assigned when adding LineSeries to a plot.

If you add a new LineSeries without its Color property set, the LineSeries will be assigned a Color (assigned to the ActualColor property) based on the number of LineSeries in the plot with its Color property still set to its default value (0x000001). Therefore, if you have 5 LineSeries in a plot of which 2 still have their Color property set to default, the Color assigned to the third LineSeries will be the third Color in the DefaultColors IList<> collection.

If you elect to assign a Color to a LineSeries (thereby assigning a non-default value to its Color property) and Refresh the plot, all other LineSeries may have their ActualColor property re-assigned a new color based on the number of LineSeries with default Colors remaining in the Series collection.

For example: First four colors in the DefaultColors IList<> collection are Red, Blue, Brown and Violet. The first LineSeries added with a default Color will have Red assigned to its ActualColor. Blue for the second, Brown for the third. Now, if you assign say Yellow to the second LineSeries and refresh the plot, you will find that the first LineSeries remains Red but the third LineSeries (previously Brown) will be re-assigned to Blue (since its the next in line in the IList<>).

In short, default / random colors are only assigned if their Color property is set to its default value of 0x000001. Once added to a plot, updating its Color can affect the color of other LineSeries (defpending on their order in the Series collection with regard to other LineSeries with a default Color property.

Hope this helps and thank you for this excellent library.


objo wrote at 2014-01-10 09:20:

Thanks Jean, great explanation!