jeudi 2 avril 2015

WinForm chart issue

I'm trying to create a chart based on a dataTable. The table contains only two columns, names and count:



+-------+-------+
| names | count |
+-------+-------+
| name1 | 650 |
+-------+-------+
| name2 | 0 |
+-------+-------+
| name3 | 211 |
+-------+-------+
| name4 | 50 |
+-------+-------+


I want the Y axis to be the count. I want a column to be generated for each name and labelled with the actual names.


This is what I tried:



int max = 0;
for (int i = 0; i < table.Rows.Count; i++)
{
if (Convert.ToInt32(table.Rows[i][1]) > max) max = Convert.ToInt32(max.Rows[i][1]);
}
chart1.ChartAreas.Add("area");
chart1.ChartAreas[0].AxisY.Minimum = 0;
chart1.ChartAreas[0].AxisY.Maximum = max;
chart1.ChartAreas[0].AxisY.Interval = max/ 10;

for (int i = 0; i < table.Rows.Count; i++)
{
chart1.Series.Add(table.Rows[i][0].ToString());
}
for (int i = 0; i < table.Rows.Count; i++)
{
chart1.Series[i].Points.AddXY(table.Rows[i][0].ToString(), Convert.ToInt32(table.Rows[i][1]));
}


And this is what I get, which is not quite what I expected: enter image description here


Aucun commentaire:

Enregistrer un commentaire