【发布时间】:2015-05-26 16:54:51
【问题描述】:
我最近一直在使用OxyPlot,想知道是否有办法覆盖 PlotSeries / PlotModel 的默认调色板?
我知道我可以为每个系列单独设置颜色,但最好有一个颜色数组,然后将其应用于模型/系列。
【问题讨论】:
标签: c# charts color-palette oxyplot
我最近一直在使用OxyPlot,想知道是否有办法覆盖 PlotSeries / PlotModel 的默认调色板?
我知道我可以为每个系列单独设置颜色,但最好有一个颜色数组,然后将其应用于模型/系列。
【问题讨论】:
标签: c# charts color-palette oxyplot
您可以更改PlotView的Model中的DefaultColors列表:
plotView.Model.DefaultColors = new List<OxyColor>
{
OxyColors.Red,
OxyColors.Green,
OxyColors.Blue,
OxyColor.FromRgb(0x20, 0x4A, 0x87)
};
为了更简单,可以使用OxyPalettes的类方法:
plotView.Model.DefaultColors = OxyPalettes.Jet(plotView.Model.Series.Count).Colors;
【讨论】:
添加到另一个答案,如果您想为应用程序中的每个绘图使用相同的颜色集,您可以在您的 xaml 资源中设置这些颜色。例如,如果您想使用默认的Seaborn palette,您可以将以下内容添加到您的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>
【讨论】: