Easy Way To Plot Graphs With C
Easy Way To Plot Graphs With C
Visual Studio 2010
Ola, amigos! Here I am again to another tutorial. This time I’m going to give you a brief
tutorial teaching you how to plot graphs using a component called Chart, its recommended
for you to take a look at its documentation before.
Well, for almost for years developing in C#, last month was the first time I ended up
drawing graphs in an application I’m developing. After a couple of hours looking at the
internet, I found an easy way to do it. You only need to add the coordinates, x and y, or
only one of those and that’s it. It’s done!
I first created a new application, added a button and the Chart component.
It looked like this.
So, before start coding, let’s create a collection. But, what is a collection? In simple words,
a collection is your graph, the Chart component gives you the opportunity to plot more than
one graph in the same place, thus a collection is a list of coordinates that you be shown to
you.
chart1.Series["test1"].ChartType =
SeriesChartType.FastLine;
chart1.Series["test1"].Color = Color.Red;
chart1.Series["test2"].ChartType =
SeriesChartType.FastLine;
chart1.Series["test2"].Color = Color.Blue;
As you could see, I just random a few numbers and added to my both series.
Below the for there are 4 lines of code where I set up how I’d like my graphs to be like. If
you dont want a line graph, you can just change the enumerator SeriesChartType.
That’s the result. It’s a little bit weird cause of my coordinates, but I just wanted to show
you how simple is that.
That’s it for now!
Anything you’d like to add, please use the comment area below.