-1

I am developing a winform application to display a line chart with the use of LiveCharts. How can I draw a vertical line at a certain x coordinate? Thanks in advance.

pado
  • 123
  • 1
  • 11
  • Could this be what you're looking for? https://stackoverflow.com/a/42590850/13108684 – ConnorTJ Oct 28 '21 at 13:49
  • @ConnorTJ I think it's about WPF. I should simply draw a line at the maximum value of the graph. – pado Oct 28 '21 at 13:54
  • Hi Pado, yeah, the answer at the link was for WPF, but the C# code to actually plot the lines should be re-useable for Winforms with possibly some slight alterations! – ConnorTJ Oct 28 '21 at 14:00
  • yes, but it's not what i've looking for: i don't need to add a new lineSeries, i only need to draw a simple line (visual element) at a single x coordinate. – pado Oct 28 '21 at 14:04
  • Ahh, possibly take a look at the `Paint` method something like: https://stackoverflow.com/questions/41263864/winforms-chart-draw-a-allowed-area-on-line-chart except you can modify the code to just draw a single vertical line at the X position – ConnorTJ Oct 28 '21 at 14:09

1 Answers1

0

I found:

        cartesianChart.AxisX.Add(new Axis
        {
            //IsMerged = true,
            Sections = new SectionsCollection
            {
                new AxisSection
                {
                    Value = x_best,
                    Stroke = System.Windows.Media.Brushes.Red,
                    StrokeThickness = 3,
                    StrokeDashArray = new System.Windows.Media.DoubleCollection(new [] {10d})

                }
            }
        });
pado
  • 123
  • 1
  • 11
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Milad Dastan Zand Oct 28 '21 at 16:01