【问题标题】:Add vertical line to LiveCharts.WinForms.CartesianChart将垂直线添加到 LiveCharts.WinForms.CartesianChart
【发布时间】:2021-12-28 18:23:31
【问题描述】:

下面是我的 LiveChart.WinForms.CartesianChart,我想知道如何在下面的图表中添加一条垂直线 - 例如,我想在 8 月 21 日的点添加一条黑色垂直线(带有工具提示)并且想知道我该怎么做?

这是我正在使用的代码:

        cartesianChart1.AxisX.Add(new Axis
        {
            Labels = myDateLabels,
            Separator = new LiveCharts.Wpf.Separator { Step = 1 },
            LabelsRotation = 270
        });

        cartesianChart1.AxisY.Add(new Axis
        {
        });
        cartesianChart1.LegendLocation = LegendLocation.Bottom;

        var axisSection = new AxisSection
        {
            Stroke = System.Windows.Media.Brushes.Black,
            StrokeThickness = 1,
            Value = 2
        };

        cartesianChart1.AxisX.Add(new Axis
        {
            Sections = new SectionsCollection
            {
                axisSection
            }
        });

        SeriesCollection series = new SeriesCollection();

        series.Add(new LineSeries { Title = "Sign Ups", Values = signUpsValues, Stroke = System.Windows.Media.Brushes.Blue, Fill = System.Windows.Media.Brushes.Transparent });

        cartesianChart1.Series = series;

【问题讨论】:

    标签: c# visual-studio winforms user-controls livecharts


    【解决方案1】:

    你只需要添加如下代码:根据你的情况修改Value的值。

    var axisSection = new AxisSection {
        Stroke=Brushes.Black,//colocr
        StrokeThickness=1,
        Value=2,//Modify this.
    };
    
    cartesianChart1.AxisX.Add(new Axis {
                Sections=new SectionsCollection
             {
                 axisSection         
            }
    });
    

    输出:

    如果您对此有任何疑问,请在下方添加评论。

    【讨论】:

    • 我在Winforms 中使用了LiveChartsLiveCharts.Wpf
    • 这是我尝试做的,但您提供的代码似乎没有做任何事情 - 我的图表仍然与问题中的相同
    • 你修改了value的值吗?修改后,将上述代码放入build函数中。如果可能,请粘贴您的代码,我会帮助您修改它。如图修改后,我有竖线。你的要求和我的照片一样吗?
    • 最好把你所有的代码都粘贴过来,不知道我们的代码哪里不一样。
    • 修改value的值,确认表名是否相同。
    猜你喜欢
    • 2020-09-28
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    • 2019-05-05
    • 2021-03-09
    • 2020-05-16
    • 2017-04-04
    相关资源
    最近更新 更多