winforms - C# Chart showing unnecessary changes -


unnecessary changes in chart(image link) working on c#,winform.this code.i trying show chart number of people registered in selected date working @ first selection of date datetimepicker, @ second selection , second time button click showing unexpected changes(please refer image perfect understanding). don't want changes want every time user pick date has perfect output of 5 bars.how can that? please help!thanks in advance.

private void loadchart_click(object sender, eventargs e)     {         string date1 = datetimepicker1.value.tostring("dd-mm-yyyy");         string date2 = datetimepicker1.value.adddays(1).tostring("dd-mm-yyyy");         string date3 = datetimepicker1.value.adddays(2).tostring("dd-mm-yyyy");         string date4 = datetimepicker1.value.adddays(3).tostring("dd-mm-yyyy");         string date5 = datetimepicker1.value.adddays(4).tostring("dd-mm-yyyy");          string cmdtextdate = "select * allinonetable date=@date";         oledbcommand commanddate = new oledbcommand(cmdtextdate, my_con);         commanddate.commandtext = cmdtextdate;         commanddate.parameters.addwithvalue("@date", date1);         dataset data = new dataset();         oledbdataadapter da = new oledbdataadapter(commanddate);         da.fill(data);         int = data.tables[0].rows.count;          string cmdtextdate2 = "select * allinonetable date=@date";         oledbcommand commanddate2 = new oledbcommand(cmdtextdate2, my_con);         commanddate2.commandtext = cmdtextdate2;         commanddate2.parameters.addwithvalue("@date", date2);         dataset data2 = new dataset();         oledbdataadapter da2 = new oledbdataadapter(commanddate2);         da2.fill(data2);         int b = data2.tables[0].rows.count;          string cmdtextdate3 = "select * allinonetable date=@date";         oledbcommand commanddate3 = new oledbcommand(cmdtextdate3, my_con);         commanddate3.commandtext = cmdtextdate3;         commanddate3.parameters.addwithvalue("@date", date3);         dataset data3 = new dataset();         oledbdataadapter da3 = new oledbdataadapter(commanddate3);         da3.fill(data3);         int c = data3.tables[0].rows.count;          string cmdtextdate4 = "select * allinonetable date=@date";         oledbcommand commanddate4 = new oledbcommand(cmdtextdate4, my_con);         commanddate4.commandtext = cmdtextdate4;         commanddate4.parameters.addwithvalue("@date", date4);         dataset data4 = new dataset();         oledbdataadapter da4 = new oledbdataadapter(commanddate4);         da4.fill(data4);         int d = data4.tables[0].rows.count;          string cmdtextdate5 = "select * allinonetable date=@date";         oledbcommand commanddate5 = new oledbcommand(cmdtextdate5, my_con);         commanddate5.commandtext = cmdtextdate5;         commanddate5.parameters.addwithvalue("@date", date3);         dataset data5 = new dataset();         oledbdataadapter da5 = new oledbdataadapter(commanddate5);         da5.fill(data5);         int f = data5.tables[0].rows.count;          this.chart1.series["series1"].points.addxy(date1, a);         this.chart1.series["series1"].points.addxy(date2, b);         this.chart1.series["series1"].points.addxy(date3, c);         this.chart1.series["series1"].points.addxy(date4, d);         this.chart1.series["series1"].points.addxy(date5, f);     } 

try clearing series (below) re-add new data afterwards. not sure if that's 100% want, seems it.

series.points.clear(); //for code this.chart1.series["series1"].points.clear(); 

also on side note - should call select * from or multiple calls database retrieve information can done single query.

if you're using sql, group by , union keywords sql queries. it'll allow condense multiple calls one. separate see fit, if see need. linq come in handy here.

this example show overview of i'm talking if it's not contextually same. little more advanced however.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -