【发布时间】:2020-04-29 23:00:39
【问题描述】:
我创建了一个多系列折线图,但我需要在循环的开始和结束时添加垂直线标记。我到处研究过,找不到怎么做。我需要从后面的代码中执行此操作,因为每个图表的值都会发生变化。
非常感谢任何帮助。
【问题讨论】:
我创建了一个多系列折线图,但我需要在循环的开始和结束时添加垂直线标记。我到处研究过,找不到怎么做。我需要从后面的代码中执行此操作,因为每个图表的值都会发生变化。
非常感谢任何帮助。
【问题讨论】:
我发现添加垂直线的唯一方法是在特定 x 和 y 值处添加数据点。请注意,这两个数据点具有相同的 X 值。一个从 100 的 y 值开始,另一个从 1200 开始,因此它是一条垂直直线。
//******************************************************
//This is for plotting vertical lines
//******************************************************
lsStartCycle.IndependentValueBinding = new Binding("Key");
lsStartCycle.DependentValueBinding = new Binding("Value");
lsStartCycle.ItemsSource = new KeyValuePair<DateTime, int>[]
{
new KeyValuePair<DateTime,int>(MyFunctions.StartCycleTime, 100),
new KeyValuePair<DateTime,int>(MyFunctions.StartCycleTime, 1200) };
在 XAML 中我添加了一个新系列。
<DVC:LineSeries Name="lsStartCycle" Title="Cycle Start"
ItemsSource="{Binding}"
DataPointStyle="{StaticResource myLineDataPointStyle}"
PolylineStyle="{StaticResource DashedPolyLine}"
LegendItemStyle="{StaticResource HideLegend}"
IsSelectionEnabled="True">
</DVC:LineSeries>
注意:我的建议是远离 WPF 工具包图表。改用 MS Chart 控件,效果会更好。我最终改用了那个图表。
【讨论】: