Search code examples
iosxamarinxamarin.iosoxyplot

Xamarin.iOS, OxyPlot How to convert UIColor to OxyColor


I'm using OxyPlot to plot bar charts in xamarin.ios project. I've to change the bar colors of the barchart and it seems it takes only OxyColor, and I'm getting #code from my back end.

series.Items.Add(new ColumnItem() { Value = Double.Parse(graph.valueList[i]), Color = OxyColors.Green });

How can I change the hex code to OxyColor. or even UIColor to OxyColor?


Solution

  • OxyColor has a Parse method, the string in the format "#FFFFFF00" or "255,200,180,50"

    i.e:

    OxyColor.Parse("#FFFF0000")
    OxyColor.Parse("#FF0000")
    OxyColor.Parse("255,0,0")
    OxyColor.Parse("255,255,0,0")
    

    Ref: https://github.com/oxyplot/oxyplot/blob/4db3c45a2acc86b7b11816462cb4f2850c709a11/Source/OxyPlot/Rendering/OxyColor.cs