Azy Qadir
Azy Qadir

Reputation: 155

how to add chart in visual studio 2012 c# windows based application

Hi, I am newbie in visual studio .net I am developing a project of energy consumption calculator in which I am drawing the two annual energy cost in xy chart like energycost1 and energycost2 .
I drag the chart from toolbox into window form and I wanted to show these two energy cost on this chart. on x-axis I want to show nothing but on y-axis I wanted to show the energy values like this 200k , 400k , 600k , 800k 1M.
can anyone help me to create this chart for me I have no idea how to draw these two value on chart.

Upvotes: 1

Views: 4478

Answers (1)

tmwoods
tmwoods

Reputation: 2413

You can use the axis properties for the chart you have created (let's call it chData).

chData.Titles.Add("Voltage Data");
chData.ChartAreas[0].AxisX.Title = "Readings";
chData.ChartAreas[0].AxisY.Title = "Voltage (V)"; 

Or you can add a secondary axis:

chData.ChartAreas[0].AxisY2.Title = "Current (A)";

There are a ton of properties you can play with, just check the Axis libraries for a full list. In there are the properties for intervals, manually adding tick titles, etc.

To add individual series, use the following code:

chData.Series.Add("Battery 1");

then you can add data points to it like this:

 for (int i = 0; i < dataSize - 1; i++)
 {
     chData.Series[0].Points.Add(array[i]);
 }

where array[] is the array that has your data you want to show in it. You can change the visual type of chart and most other properties from the property window under Series.

Upvotes: 2

Related Questions