mobilecontrols-402320-xamarin-forms-charts-examples-color-segments.md
A segment colorizer allows you to color-code segments of line and area series.
ChartView supports the point-based segment colorizer that paints line/area segments with colors of point markers, and uses color gradients for segments between different color points.
To colorize line segments:
Assign a colorizer object to the series’s SegmentColorizer property ( Line1SegmentColorizer / Line2SegmentColorizer for a range area series).
Assign one of the following objects to the segment colorizer’s PointColorizer property:
In this example, the spline chart displays the temperature curve colored based on ranges of temperature values.
Create a data source - a list of objects that define data points with date-time arguments and numeric values.
Assign a GradientPointBasedSegmentColorizer object to the SplineSeries.SegmentColorizer property.
Assign a ValueBandPointColorizer object to the GradientPointBasedSegmentColorizer.PointColorizer property. Populate the colorizer’s ColorStops collection with ColorStop objects that specify colors for ranges of temperature values.
To colorize area segments:
Assign a fill colorizer object to the series’s FillColorizer property.
Assign a segment colorizer object to the fill colorizer’s SegmentColorizer property.
The following table lists segment colorizers that fill colorizers support:
Assign one of the following objects to the segment colorizer’s PointColorizer property:
In this example, the area chart visualizes the visible light spectrum.
Create a data source - a list of objects that define data points with numeric arguments (wavelength) and values (intensity).
Create a colorizer class (LightSpectorColorizer, in this example) that implements the ICustomPointColorizer interface.
Implement the GetColor method to return a data point’s color based on a ColoredPointInfo object passed to the method as a parameter. Use the ColoredPointInfo.NumericArgument property to obtain the data point’s argument value.
This class should also implement the ICustomPointColorizer.GetLegendItemProvider method and the ILegendItemProvider interface to specify legend items that show wavelength colors.
Assign a SegmentBasedFillColorizer object to the AreaSeries.FillColorizer property.
Set the SegmentBasedFillColorizer.SegmentColorizer property to a GradientPointBasedSegmentColorizer object, and assign a LightSpectorColorizer object to the GradientPointBasedSegmentColorizer.PointColorizer property.