Under review

Keep LineSerie Colors

Oystein Bjorke 6 years ago updated by Kaviraj Muruganathan 4 years ago 5
This discussion was imported from CodePlex

oloopy wrote at 2013-04-27 02:30:

Currently I am using OxyPlot to plot vehicle trajectory data. The total number of lines would be around 2000. OxyPlot does a good job to render these lines efficiently and give them a different color automatically.

But I noticed that colors of lines would be changed if I remove one of lines. And it seems like the color would be rearranged by default color order, which is from green, khaki, red...

For example, I plot three vehicle trajectories below.


ID 2270 is in green. ID 2276 is in khaki. ID 2281 is in red. And the order I plot them is start from 2270, then 2276, finally 2281.


Now I remove ID 2276. Then ID 2281's color changed to be khaki from red.

I would like to know if there is a way to keep the line color as it will help user focus on certain line they are working on.

Here lists my code. It's quite simple.

var lineSerie = new LineSeries();

data.ToList().ForEach(d =>lineSerie.Points.Add(new DataPoint(Convert.ToDouble(d.X), Convert.ToDouble(d.Y))));



Thank you guys!

objo wrote at 2013-04-29 13:28:

I think you should keep your own list of colours, and set the colour for each series manually!
I see that OxyPlot could assign the automatic colour only once, but this requires some changes to the code. Create an issue if you think this is an important feature to add!

objo wrote at 2013-04-29 13:30:

btw, what kind of vehicles are you plotting trajectories for? I am curious :)
Is it possible to get access to default color collection?
As far as I understand if a Series has it's default colour (OxyColors.Undefined), then the PlotModel it's on will draw it with a colour out of PlotModel.DefaultColors, which you can set in your code. Looking at the source these are the defaults it has:

this.DefaultColors = new List<OxyColor><br>
        OxyColor.FromRgb(0x4E, 0x9A, 0x06),
        OxyColor.FromRgb(0xC8, 0x8D, 0x00),
        OxyColor.FromRgb(0xCC, 0x00, 0x00),
        OxyColor.FromRgb(0x20, 0x4A, 0x87),

From Here

Indentation needs to be fixed on it lol.
Side note: I have no idea how to display code on UserEcho.
Nick, thank you!

Yes, I can set series color in code and it won't be changed. I think if we let an user to show and hide series we should keep their colors.

In order to get the default behaviour it's also necessary to set a series linestyle.

My solution
int _currentColorIndex;
List<OxyColor> LineColors { get; set; }
ourLineSeries.LineStyle = (LineStyle)((_currentColorIndex / LineColors.Count) % (int)LineStyle.None);
ourLineSeries.Color = LineColors[_currentColorIndex++ % LineColors.Count];
Under review
@nick: switch to <> mode and use <pre>...</pre> to display code. I don't know if it is possible to do it with syntax highlighting.

I updated your code samples :-)