Override OxyPlot's default color palette

I used OxyPlot recently and wondered if there is a way to override the default color palette PlotSeries / PlotModel?

I know that I can set the color separately for each series, but it would be nice to have an array of colors, and then apply it to the model / series.

+5
source share
2 answers

You can change the DefaultColors list in the PlotView Model :

 plotView.Model.DefaultColors = new List<OxyColor> { OxyColors.Red, OxyColors.Green, OxyColors.Blue, OxyColor.FromRgb(0x20, 0x4A, 0x87) }; 

To make this even easier, you can use the methods of the OxyPalettes class:

 plotView.Model.DefaultColors = OxyPalettes.Jet(plotView.Model.Series.Count).Colors; 
+7
source

Adding to another answer, if you want to use the same set of colors for each plot in your application, you can set it in your xaml resources. If, for example, you want to use the standard Seaborn palette , you can add the following to your App.xaml :

 <Application.Resources> <ResourceDictionary> <x:Array Type="Color" x:Key="SeabornColors"> <Color>#4c72b0</Color> <Color>#55a868</Color> <Color>#c44e52</Color> <Color>#8172b2</Color> <Color>#ccb974</Color> <Color>#64b5cd</Color> </x:Array> <Style TargetType="oxy:Plot"> <Setter Property="DefaultColors" Value="{StaticResource SeabornColors}"/> </Style> </ResourceDictionary> </Application.Resources> 
+2
source

Source: https://habr.com/ru/post/1215923/


All Articles