首页 > 解决方案 > 如何在 WPF 工具包图表中的特定数据点添加垂直线

问题描述

我创建了一个多系列折线图,但我需要在循环的开头和结尾添加一个垂直线标记。我到处研究过,找不到怎么做。我需要从后面的代码中执行此操作,因为每个图表的值都会发生变化。

任何帮助是极大的赞赏。

标签: wpfchartstoolkit

解决方案


我发现添加垂直线的唯一方法是在特定的 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 控件,效果会更好。我最终改用了那个图表。


推荐阅读