在LiveChart中自定义单个数据的颜色

时间:2017-08-28 02:05:59

标签: c# wpf livecharts

是否可以以及如何在LiveChart中自定义单个数据颜色?我没有为后面的代码系列设置相同的颜色方案,而是喜欢以编程方式和条件方式为单个数据列着色。我想,作为一种解决方法,分离和覆盖系列就像有一个红色系列{null,null,null,7.8,null}和一个绿色系列{2,3,2,null,4}但它强烈键入,我不能传入null。

简而言之,我如何从左到右:

enter image description here

[编辑1]

我阅读了建议的链接,但是mapper似乎在LineSeries上无法正常工作。

cvValues = new ChartValues<double>() { 1.01, 2.02, 3.03, 4.04, 1.01, 2.02, 3.03, 4.04, 1.01, 2.02 };
cvUSL = new ChartValues<double>() { 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5 };
cvLSL = new ChartValues<double>() { 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5 };

DangerBrush = new SolidColorBrush(Colors.Red);

mapper1 = new CartesianMapper<double>()
        .X((value, index) => index + 1)
        .Y((value, index) => value)
        .Fill((value, index) => value > 3.5 ? DangerBrush : null)
        .Stroke((value, index) => value > 3.5 ? DangerBrush : null)
        .Fill((value, index) => value < 1.5 ? DangerBrush : null)
        .Stroke((value, index) => value < 1.5 ? DangerBrush : null);

DataContext = this; 

这是我的XAML(如果数据超出上边界或下边界,只想填充红色)

<lvc:LineSeries x:Name="lsUSL"
                Values="{Binding cvUSL}" 
                PointGeometrySize="0"
                PointForeground="White"
                Stroke = "Turquoise"
                StrokeDashArray = "8"
                StrokeThickness = "0.8"
                Fill = "Transparent"
                Configuration="{Binding mapper1}"/>

<lvc:LineSeries x:Name="lsLSL"
                Values="{Binding cvLSL}" 
                PointGeometrySize="0"
                PointForeground="White"
                Stroke = "Turquoise"
                StrokeDashArray = "8"
                StrokeThickness = "0.8"
                Fill = "Transparent"
                Configuration="{Binding mapper1}"/>

<lvc:LineSeries x:Name="lsValues"
                Values="{Binding cvValues}" 
                PointGeometrySize="5"
                PointForeground="Green"
                Stroke = "Gray"
                StrokeThickness = "1"
                Fill = "Transparent"
                Configuration="{Binding mapper1}"/>

1 个答案:

答案 0 :(得分:2)

在StackOverflow上查看此Question,在gitthub上查看此Issue。我想你可以在那里找到答案。

相关问题