Lineseries.Color bug, help

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

OverDriver wrote at 2014-07-24 03:20:

Hi all, thanks for the library!
I wanna keep the color patter of creating the new line while getting the color of the line plotted. But this: OxyPlot.WindowsForms.ConverterExtensions.ToColor(tmpLine.Color); code will always return same color value back.
Thanks a lot!
foreach (Plot plotItem in _plots)
            {
                var tmpLine = new LineSeries();
                tmpLine.Points.AddRange(plotItem._resampledPoints);
                tmpLine.StrokeThickness = plotItem._thickness;
                tmpLine.LineStyle = plotItem._style;
                if(_showLineTitle)
                    tmpLine.Title = plotItem._name;
                if (!(plotItem._color.Equals(System.Drawing.Color.White)))
                    tmpLine.Color = plotItem._color.ToOxyColor();
                plotItem._color = OxyPlot.WindowsForms.ConverterExtensions.ToColor(tmpLine.Color);
                model.Series.Add(tmpLine);
            }

Slxe wrote at 2014-07-24 15:11:

You're using extensions wrong, might want to look into them more =P. Try just doing
tmpLine.Color.ToColor();

OverDriver wrote at 2014-07-24 16:59:

Every time the tmpLine.Color will always give me {#00000001} while the actual color is not. I've tried changing my code to This:
foreach (Plot plotItem in _plots)
            {
                var tmpLine = new LineSeries();
                tmpLine.Points.AddRange(plotItem._resampledPoints);
                tmpLine.StrokeThickness = plotItem._thickness;
                tmpLine.LineStyle = plotItem._style;
                if (_showLineTitle)
                    tmpLine.Title = plotItem._name;
                if (!(plotItem._color.Equals(System.Drawing.Color.White)))
                    tmpLine.Color = plotItem._color.ToOxyColor();
                plotItem._color = tmpLine.Color.ToColor();

                model.Series.Add(tmpLine);
            }
Thanks so much!

Slxe wrote at 2014-07-25 16:37:

That's because LineSeries.Color is actually initialized to OxyColors.Automatic if you don't define it yourself. This allows whatever you've set to PlotModel.DefaultColors to handle giving line series colours when they're visible. You can do something similar to PlotModel.DefaultColors = OxyPalettes.HueDistinct(20).Colors to change what it gives out for automatic colours. You'll have to set the colour of the line series yourself if you want something from LineSeries.Color.

OverDriver wrote at 2014-07-26 00:17:

This information is so helpful! Thanks so much!
You're always so helpful :)
CodePlex