How to add points to line graph dynamically

Sanna Ravi
2 min readSep 24, 2014

--

Hi friends, this is my first blog going to write the article within shorten period. So i need your big patience while reading the articles.

Title of this article seems like difficult but exactly it is not. Well Let’s see how to do this in C# using visual studio 2012

Assume that you are going to show two readings in same chart ( e.g :- download rate, upload rate)

As the very first step drag the chart component from toolbox to your forms application. You can find chart component easily by seaching at the top of toolbox. Initially it is a bar graph

In the properties of chart component you can see the Series. while you clicking that following dialog box will appear

In here you can change the type of chart by changing the ChartType”. You can have four different types of chart depends on chart type. here i have used Spline type for both series “DownRate” and “UpRate

I have used System.Windows.Timer to plot the points in graph. To do that Add attribute called timer as an object of Timer and also constant double variable to set the frequent for timer.

value given to the timer will be taken in millisecond.

In the constructor initialize the timer & create a handler method to run during each session of timer

I have created a handler named “timer_Tick “ to call the private method which is plotting points in graph.

Within a private method we can use following code to plot the points to graph

Further you can have count variables to remove the old points from chart. You can use “RemoveAt()” method for Points in a specific series

Finally it’s done. Things to do is much smaller than this article……

--

--