Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override OxyPlot default color palette

I've been making use of OxyPlot lately, and was wondering if there is a way of overriding the default Color Palette of PlotSeries / PlotModel?

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

like image 895
stoic Avatar asked Mar 23 '15 15:03

stoic


2 Answers

You can change the DefaultColors list in PlotView's Model:

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

To make it even more easy, OxyPalettes's class methods can be used:

plotView.Model.DefaultColors = OxyPalettes.Jet(plotView.Model.Series.Count).Colors;
like image 64
forallepsilon Avatar answered Nov 15 '22 20:11

forallepsilon


Adding to the other answer, if you want to use the same set of colors for every plot in your application, you could set those in your xaml resources. If, for instance, you want to use the default Seaborn palette, you could 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>
like image 34
fuglede Avatar answered Nov 15 '22 19:11

fuglede