c# - WinForm chart issue -


i'm trying create chart based on datatable. table contains 2 columns, names , count:

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

i want y axis count. want column generated each name , labelled actual names.

this tried:

int max = 0; (int = 0; < 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;  (int = 0; < table.rows.count; i++) {     chart1.series.add(table.rows[i][0].tostring()); } (int = 0; < table.rows.count; i++) {     chart1.series[i].points.addxy(table.rows[i][0].tostring(), convert.toint32(table.rows[i][1])); } 

and get, not quite expected: enter image description here

change this:

for (int = 0; < table.rows.count; i++) {     chart1.series.add(table.rows[i][0].tostring()); } (int = 0; < table.rows.count; i++) {     chart1.series[i].points.addxy(table.rows[i][0].tostring(),                                     convert.toint32(table.rows[i][1])); } 

to this:

series s = chart1.series.add("names");  (int = 0; < table.rows.count; i++) {     s.points.addxy(table.rows[i][0].tostring(), convert.toint32(table.rows[i][1])); } 

your original code added 1 series each row , 1 datapoint each series. made chart place them beside each other , display sole point, each unique series color..

the new code creates 1 series , adds datapoints points collection.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - Gamma correction doesn't look properly corrected, is this linear? -