![](/img/trans.png)
[英]Line Chart with different colors on a different interval at x-axis fill in same series?
[英]Column Series With different color on a different interval at x-axis fill in same series?
我正在尝试实现速度/时间绘图 UI,我将 WPF 与 MVVM 模式和 beto-rodriguez 的实时图表一起用作我的绘图库。 我正在使用列系列。
我有两个问题:1)我必须在 x 轴的中间开始系列怎么做? 例如,如果我将最小值设置为 7,则图形将 x 轴设为 7,将其作为第一个点,但我希望 x 轴从 1 开始,但图形绘制应从 7 开始。
2)我必须在某个条件下更改系列的颜色,比如当 x= 10 我希望它显示为蓝色但当 x= 17 我想将相同的系列显示为粉红色,仅在所有点的值都休息它应该是原始颜色。
任何指针?
你有几个选择:
对每个点使用不同的系列:
<lvc:CartesianChart>
<lvc:CartesianChart.Series>
<lvc:ColumnSeries Fill="Red" />
<lvc:ColumnSeries Fill="Blue" />
您可以使用映射器来设置它们,例如: https : //lvcharts.net/App/examples/v1/wpf/Point%20State
嗨,我用这段代码解决了这个问题:在我的情况下,我需要具有不同颜色的实际小时数据的列。
背后的代码:
public Brush DangerBrushFill { get; set; } = new SolidColorBrush(Colors.DarkOrange);
public Brush DangerBrushStroke { get; set; } = new SolidColorBrush(Colors.Black);
public CartesianMapper<Double> Mapper { get; set; }
public ChartValues<double> ChartValues { get; private set; }
Mapper = Mappers.Xy<Double>()
.X((item, index) => item)
.Y((item, index) => index)
.Fill((item, index) =>
(item > 0 && index == DateTime.Now.Hour - 1) ? DangerBrushFill : null)
.Stroke((item, index) =>
(item > 0 && index == DateTime.Now.Hour - 1) ? DangerBrushFill : null);
SeriesCollection = new SeriesCollection
{
new RowSeries
{
Configuration=Mapper,
Values = ChartValues,
StrokeThickness = 3
}
};
Xml:
<lvc:CartesianChart Hoverable="False"
Series="{Binding SeriesCollection}">
我希望这对你有帮助。
1)是否有可能在开始时用 0 填充 ColumnSeries 的值? 例如 ColumnSeries 的值将是这样的,如果你想从 7 开始你的图表: {0, 0, 0, 0, 0, 0, 10, 12, 14, 16}
2)你能再举一个条件的例子吗? 你的意思是 x=10 还是 y=10? 这个问题与您的问题有关吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.