wpf - LiveCharts ColumnSeries 填充颜色

标签 wpf livecharts

我正在关注this LiveChart 文档中的示例。代码如下所示:

<lvc:CartesianChart Margin="20" Series="{Binding SeriesCollection}" LegendLocation="Left">
        <lvc:CartesianChart.AxisX>
            <lvc:Axis Title="Salesman" Labels="{Binding Labels}"></lvc:Axis>
        </lvc:CartesianChart.AxisX>
        <lvc:CartesianChart.AxisY>
            <lvc:Axis Title="Sold Apps" LabelFormatter="{Binding Formatter}"></lvc:Axis>
        </lvc:CartesianChart.AxisY>
    </lvc:CartesianChart>

它看起来很完美,并且非常适合我,但有一个问题。在此示例中,如何更改 ColumnSeriesfill 颜色?正如我之前所说,我不想实现另一个图表,因为它非常适合我,但我不知道如何更改填充颜色。

我在SO中没有找到类似的问题。

编辑

工作解决方案:

<lvc:CartesianChart Margin="20" Series="{Binding SeriesCollection}" LegendLocation="Left">
        <lvc:CartesianChart.SeriesColors>
            <lvc:ColorsCollection>
                <Color>Green</Color>
            </lvc:ColorsCollection>
        </lvc:CartesianChart.SeriesColors>
        <lvc:CartesianChart.AxisX>
            <lvc:Axis Title="Salesman" Labels="{Binding Labels}"></lvc:Axis>
        </lvc:CartesianChart.AxisX>
        <lvc:CartesianChart.AxisY>
            <lvc:Axis Title="Sold Apps" LabelFormatter="{Binding Formatter}"></lvc:Axis>
        </lvc:CartesianChart.AxisY>
    </lvc:CartesianChart>

最佳答案

您可以在 XAML 中定义一组 Color 对象,这些对象将按声明顺序隐式映射到 ColumnSeries 对象:

<lvc:CartesianChart x:Name="CartesianChart"
                    Series="{Binding SeriesCollection}">
  <lvc:CartesianChart.SeriesColors>
    <lvc:ColorsCollection>
      <Color>Red</Color>
      <Color>Orange</Color>
      <Color>LightSlateGray</Color>
    </lvc:ColorsCollection>
  </lvc:CartesianChart.SeriesColors>
</lvc:CartesianChart>

或者在 XAML 或 C# 中显式定义 ColumnSeriesFill:

public SeriesCollection SeriesCollection { get; set; } = new SeriesCollection
{
  new ColumnSeries
  {
    Title = "Series A",
    Values = new ChartValues<double> { 10, 20, 30, 20, 10},
    Fill = Brushes.CornflowerBlue
  },
  new ColumnSeries
  {
    Title = "Series B",
    Values = new ChartValues<double> { 100, 200, 300, 200, 100 },
    Fill = Brushes.DarkOrange
  }
};

关于wpf - LiveCharts ColumnSeries 填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58121690/

相关文章:

c# - 宽度和高度与屏幕像素不匹配

c# - PropertyChangedEvent 和 CanExecute 问题

c# - 自上次访问属性以来耗时

c# - 更改图例颜色实时图表

c# - WPF Windows Controller

WPF 编码的 UI 测试 : Encrypting password read from datasource

c# - 访问 WPF 项目中的文本文件

C# Winforms 实时图表 : Fire Event when rendering of CartesianChart is finished

livecharts - 如何在 LineSeries 中输入 'null' 值?

c# - 更改 LiveCharts 中轴刻度标签的格式