- Home
- Forum
- Xamarin.Forms
- Data marker label custom color
Data marker label custom color
Hi there!

I'm trying to set a custom color in the labels of my chart depending in a property of the object in my ItemSource list. I know so far that I can use the DataMarkerLabelCreated function to get the value of the point and set the color that I need depending on a condition, but what I'm looking for is having access to the entire object not just the numerical value of the LineSeries.
My ItemSource is a list of type "HealthResourcePointModel", and if the property IsEstimated is true I would be coloring the point to grey, if not just black. That's why I'm wondering in how to get access to the entire object when calling the function DataMarkerLabelCreated.
public class HealthResourcePointModel
{
public string Year { get; set; }
public decimal Value { get; set; }
/// <summary>
/// Value with the glucose unit
/// </summary>
public string ValueGlucose { get; set; }
public DateTime Date { get; set; }
public string DateFormatted { get; set; }
public Color Color { get; set; }
public string GlucoseUnit { get; set; }
public bool IsEstimated { get; set; }
}
SIGN IN To post a reply.
3 Replies
YP
Yuvaraj Palanisamy
Syncfusion Team
December 14, 2020 01:18 AM UTC
Hi Jorge Valenzuela,
Greetings from Syncfusion.
We have achieved your requirement “Custom color for series DataMarker” by using ColorModel support for ChartSeries. Please find the following code snippet for your reference.
|
foreach(var item in Data)
{
if((item as Model).Height < 75)
{
DataMarkerColors.Add(Color.Gray);
}
else
{
DataMarkerColors.Add(Color.Black);
}
} |
|
<chart:FastLineSeries x:Name="lineSeries"
ItemsSource="{Binding Data}"
XBindingPath="XValue"
YBindingPath="Height">
<chart:FastLineSeries.DataMarker>
<chart:ChartDataMarker ShowLabel="False" ShowMarker="True"/>
</chart:FastLineSeries.DataMarker>
<chart:FastLineSeries.ColorModel>
<chart:ChartColorModel Palette="Custom"/>
</chart:FastLineSeries.ColorModel>
</chart:FastLineSeries> |
|
lineSeries.ColorModel.CustomBrushes = (Chart.BindingContext as ViewModel).DataMarkerColors;
|
Also, we have prepared sample for your reference. Please find the sample from the below link.
Output:
Regards,
Yuvaraj.
JV
Jorge Valenzuela
December 14, 2020 06:03 AM UTC
Thank you very much!
This is exactly what I needed and works very nice.
This is exactly what I needed and works very nice.
Kind regards
HM
Hemalatha Marikumar
Syncfusion Team
December 14, 2020 07:00 AM UTC
Hi Jorge Valenzuela,
Thanks for your feedback.
Regards,
Hemalatha M.
Hemalatha M.
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
JV Jorge Valenzuela
- Dec 10, 2020 01:10 PM UTC
- Dec 14, 2020 07:00 AM UTC