Hi there,
I have a dynamic SFChart based on data retrieved from a REST service.
The data is populate within the constructor of my view modal which is derived from SFChartDataSource.
Within my ViewController I set the ColorModel to Custom and insert the colors required. However, what I need to do is display different colors based on whether the value of the column is > 50.
The GetDataPoint method checks this value and toggles the Series color - stepping through the code at run time I can see the code does try to change the color. However, what renders on the screen is simply the colors in the order specified in the ColorModel property.
I have the following methods inside my derived SFChartDataSource:
IS there any way set the color of each DataPoint or Column indvidually and dynamically based on values?
public override SFChartDataPoint GetDataPoint(SFChart chart, nint index, nint seriesIndex)
{
if (seriesIndex == 0)
{
SFSeries series = this.GetSeries(chart, index);
SFChartDataPoint bar = actuals.GetItem<SFChartDataPoint>((nuint)index); // actuals being my custom NSMutableArray of values
NSNumber value = bar.YValue as NSNumber;
// if the learner has achieved 50% of vial (100% of target) display light blue
if(value.Int32Value >= 50)
{
series.Color = Colors.Blue;
} else {
series.Color = Colors.Ochre;
}
return bar;
}
return remainders.GetItem<SFChartDataPoint>((nuint)index);
}
public override nint GetNumberOfDataPoints(SFChart chart, nint index)
{
return (nint)actuals.Count;
}
public override SFSeries GetSeries(SFChart chart, nint index)
{
SFStackingColumnSeries series = new SFStackingColumnSeries();
series.EnableTooltip = true;
return series;
}
Also, where is the markdown for code on these forums?