【问题标题】:Override OxyPlot default color palette覆盖 OxyPlot 默认调色板
【发布时间】:2015-05-26 16:54:51
【问题描述】:

我最近一直在使用OxyPlot,想知道是否有办法覆盖 PlotSeries / PlotModel 的默认调色板?

我知道我可以为每个系列单独设置颜色,但最好有一个颜色数组,然后将其应用于模型/系列。

【问题讨论】:

    标签: c# charts color-palette oxyplot


    【解决方案1】:

    您可以更改PlotViewModel中的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;
    

    【讨论】:

    • 创建后如何引用颜色 FromRgb?
    • @DevDave 为什么不将其保存到局部变量?或者你是什么意思?
    【解决方案2】:

    添加到另一个答案,如果您想为应用程序中的每个绘图使用相同的颜色集,您可以在您的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-21
      相关资源
      最近更新 更多