11

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.

stoic
  • 4,700
  • 13
  • 58
  • 88

3 Answers3

18

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;
forallepsilon
  • 360
  • 2
  • 13
6

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>
fuglede
  • 17,388
  • 2
  • 54
  • 99
0

Valid for OxyPlot 2.1 and above

From OxyPlot version 2.1.0 and above, the Plot class and its associated components have been moved to OxyPlot.Contrib.Wpf, as described in the release information.

Hence the App.xaml example shall be written as:

<Application x:Class="Viewer.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:oxycontrib="http://oxyplot.org/wpf/contrib"
             StartupUri="View/MainWindow.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="oxycontrib:Plot">
                <Setter Property="DefaultColors" Value="{StaticResource SeabornColors}"/>
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>

Don't forget to add the Oxyplot.Contrib* package from NuGet manager to your C# solution:

enter image description here

CKE
  • 1,533
  • 19
  • 18
  • 29