如何在WPF工具包图表中的特定数据点上添加一条垂直线?

问题描述 投票:0回答:1

我已经创建了一个多系列线图,但我需要在一个周期的开始和结束时添加一个垂直线标记。我到处研究,但找不到如何做到这一点。 我需要从后面的代码来做,因为值会随着每个图表的变化而变化。

任何帮助都是非常感激的。

wpf charts toolkit
1个回答
0
投票

我找到的添加垂直线的唯一方法是在一个特定的x和y值处添加一个数据点。 注意,两个数据点的X值是一样的。 其中一个在y值100开始,另一个在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 Toolkit Chart。 使用MS Chart控件代替,它的效果要好得多。 我最终使用了那个图表来代替。

© www.soinside.com 2019 - 2024. All rights reserved.