【问题标题】:How to add a vertical line at a specific datapoint in WPF Toolkit Chart如何在 WPF 工具包图表中的特定数据点添加垂直线
【发布时间】:2020-04-29 23:00:39
【问题描述】:

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

非常感谢任何帮助。

【问题讨论】:

    标签: wpf charts toolkit


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 2020-08-23
      相关资源
      最近更新 更多