Chart for WinRT > Chart Features > Style and Appearance > Setting Custom Colors at Run-time |
You can set different colors for the data point in the same series using the DataSeries.PlotElementLoaded event like the following:
C# |
Copy Code
|
---|---|
DataSeries ds = new DataSeries() { ValuesSource = new double[] {-2, -1, 1, 2, 2, 1, -1, -3 } }; SolidColorBrush red = new SolidColorBrush(Colors.Red); SolidColorBrush blue = new SolidColorBrush(Colors.Blue); ds.PlotElementLoaded += (s, e) => { PlotElement pe = (PlotElement)s; if (pe != null && pe.DataPoint.PointIndex >= 0) // only points { // set color depending on point value if (pe.DataPoint.Value >= 0) pe.Fill = red; else pe.Fill = blue; } }; c1Chart1.Data.Children.Add(ds); c1Chart1.ChartType = ChartType.LineSymbols; |