replace a chart.serie with new values

Hans 251 Reputation points
2020-11-21T08:36:35.643+00:00

Is it possible to empty 1 serie in a chart that is constantly being built up with the help of a timer and fill it with 1 value? So that a straight line is put in the chart for this series.
So i want to update the Yvalue of a chart.serie. I found that i can read the Yvalues of a serie, but i do not know how to update them.
(I use c# winforms)

Greatings

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118K Reputation points
    2020-11-21T10:09:38.283+00:00

    Check if this code meets expectations:

    var points = chart1.Series[0].Points;
    
    for( var i = 0; i < points.Count; ++i )
    {
        points[i].YValues[0] = 1;
    }
    
    chart1.Invalidate( );
    

    or

    foreach( var p in chart1.Series[0].Points )
    {
        p.YValues[0] = 1;
    }
    
    chart1.Invalidate( );
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.