Wpf LiveCharts ColumnSeries填充颜色
下面是LiveChart文档中的示例。代码如下所示:Wpf LiveCharts ColumnSeries填充颜色,wpf,livecharts,Wpf,Livecharts,下面是LiveChart文档中的示例。代码如下所示: <lvc:CartesianChart Margin="20" Series="{Binding SeriesCollection}" LegendLocation="Left"> <lvc:CartesianChart.AxisX> <lvc:Axis Title="Salesman" Labels="{Binding Labels}"></lvc:Axis&
<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>
您可以在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>
我相信你的解决方案是可行的,但是你能解释一下如何在我的例子中添加特定的颜色吗?如何编辑此代码以在我的解决方案中添加此
颜色集合
?因为当我添加你提到的这行代码(lvc:ColorsCollection
)时,我的图表没有显示。你能用ColorsCollection
更新你的代码吗?这样我们就可以看看有什么问题了?@michasaucer你知道如何更改单列颜色吗?此示例更改了整个列系列。我需要在运行时更改单列颜色。谢谢对不起,我不知道。我用LIVECTRAMS做一个项目。
<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>
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
}
};