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
To assist with understanding the requirements I have attached an image of the chart I am trying to render.
I have the labels and center line - as well as the data plotted correctly. The only missing ingredient is the color based upon whether it's above or below the 50% line. I looked into CustomRenderers however no joy.
(Also is there a way of centering text using PrimaryAxis.LabelStyle?)
MEManivannan Elangovan Syncfusion Team November 4, 2016 06:27 PM UTC
Thanks for contacting Syncfusion support.
We can achieve your requirement different segment color based on datapoint value by using the properties CustomColors and Palette, which is available in ColorModel property of series and centering the text of PrimaryAxis.LabelStyle by adjusting the Margin property of LabelStyle.
We have prepared a sample for your requirement and it can be downloaded from the following location.