Win Form Charting

后端 未结 4 1169
不思量自难忘°
不思量自难忘° 2020-12-20 15:59

I may be asking the wrong question, but what I need is to add a \"Guide Line\" to my windows form chart. In other words I have a chart with a simple data series and I need t

相关标签:
4条回答
  • 2020-12-20 16:13

    You can add a StripLine.

    Use StripWidth property to set line position:

    var series = chart1.Series[0]; //series object
    var chartArea = chart1.ChartAreas[series.ChartArea];
    chartArea.AxisY.StripLines.Add(new StripLine
                                               {
                                                   BorderDashStyle = ChartDashStyle.Dash,
                                                   BorderColor = Color.DarkBlue,
                                                   StripWidth = 80//Here is your y value
                                               });
    

    UPDATE: Previous version of this answer used Interval instead of StripWidth. As @dthor correctly pointed out in the comments setting the Interval will draw a repeated strip line. In the example above, Interval is set to 0 by default.

    0 讨论(0)
  • 2020-12-20 16:13

    I've never used charts, but HorizontalLineAnnotation sounds promising.

    0 讨论(0)
  • 2020-12-20 16:23

    Apologies for repeating Don Kirkby's answer, but I don't have the rep to add a comment yet.

    Using HorizontalLineAnnotation you can set the ClipToChartArea which will limit the extent of the line to within the chart, to solve the problem you mentioned.

    ChartArea area = ...;
    
    var line = new HorizontalLineAnnotation();
    line.IsInfinitive = true; // make the line infinite
    line.ClipToChartArea = area.Name;
    line.LineDashStyle = ChartDashStyle.Dash;
    

    Assuming your y-axis holds values on a scale of 0..1 then you can attach the line to the Y-Axis using line.AxisY = area.AxisY, which results in its position being interpreted as an axis value, then set line.Y = 0.8; to attach at the 80% position.

    0 讨论(0)
  • 2020-12-20 16:24

    You can add dots to the frame with a loop that has for example 900 loop for 1 to 9 values. For each loop the compiler will calculate the value and left a dot for that perimeter and another for the next one so it will looks like a line of a equation :)

    0 讨论(0)
提交回复
热议问题