WPF Charting Documentation - SciChart WPF Charts SDK v5.x
Worked Example - PaletteProviders in MVVM

Worked Example: PaletteProviders in MVVM

PaletteProviders are covered in detail in Paletted Series. Declaring a PaletteProvider in MVVM can be done via a Style or in the ViewModel. Since PaletteProviders are simply Plain CLR Objects we would recommend creating them in the ViewModel.

ViewModel
PaletteProviders in MVVM
Copy Code
// Declare a LineRenderableSeries with a PaletteProvider
SeriesViewModels.Add(new LineRenderableSeriesViewModel()
{
   DataSeries = _xyData,
   StyleKey = "LineSeriesStyle0" ,
   PaletteProvider = new MyCustomPaletteProvider,
});

// Where MyCustomPaletteProvider is defined as
public class MyCustomPaletteProvider : IStrokePaletteProvider
{
       private XyDataSeries<double, double> _theSourceData;

       public void OnBeginSeriesDraw(IRenderableSeries series)
       {
             // OnBeginSeriesDraw is a good place to cache dataseries
             _theSourceData = (XyDataSeries<double, double>) series.DataSeries;
       }

       public Color? OverrideStrokeColor(IRenderableSeries series,
                              int index, IPointMetadata metadata)
       {
             if (_theSourceData.YValues[index] > 0.5)
                return Colors.Red;
               
             return null;       
       }
}

 

 

 


SCICHART ® is a Registered Trademark in the UK, US and EEC. Copyright SciChart Ltd 2011-2018.

Email us to give feedback!