C# data chart in x axis shows multiple times cities windows form -
guru's please halp poor padawan.
i'm trying display chart values gave in database. in x- axis want example 1 city called "rotterdam", gives me multiple times rotterdam in x-axis other rows.
this code
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace windowsformsapplication1 { public partial class form2 : form { public form2() { initializecomponent(); } private void form2_load(object sender, eventargs e) { // todo: line of code loads data 'official_databasedataset.fietsdiefstal' table. can move, or remove it, needed. this.fietsdiefstaltableadapter.fill(this.official_databasedataset.fietsdiefstal); } private void datagridview1_cellcontentclick(object sender, datagridviewcelleventargs e) { } private void button2_click(object sender, eventargs e) { chart1.series["fietsdiefstal"].xvaluemember = "plaats"; chart1.series["fietsdiefstal"].yvaluemembers = "begintijd"; chart1.datasource = official_databasedataset.fietsdiefstal; chart1.databind(); } private void button1_click(object sender, eventargs e) { try { fietsdiefstalbindingsource.endedit(); fietsdiefstaltableadapter.update(official_databasedataset.fietsdiefstal); messagebox.show("your data has been succesfully saved.", " message", messageboxbuttons.ok, messageboxicon.information); } catch(exception ex) { messagebox.show(ex.message, "message", messageboxbuttons.ok, messageboxicon.error); } } private void chart1_click(object sender, eventargs e) { } private void fillbytoolstripbutton_click(object sender, eventargs e) { try { this.fietsdiefstaltableadapter.fillby(this.official_databasedataset.fietsdiefstal); } catch (system.exception ex) { system.windows.forms.messagebox.show(ex.message); } } private void time1300toolstripbutton_click(object sender, eventargs e) { try { this.fietsdiefstaltableadapter.time1300(this.official_databasedataset.fietsdiefstal); } catch (system.exception ex) { system.windows.forms.messagebox.show(ex.message); } } private void timetoolstripbutton_click(object sender, eventargs e) { try { this.fietsdiefstaltableadapter.time(this.official_databasedataset.fietsdiefstal, param1toolstriptextbox.text); } catch (system.exception ex) { system.windows.forms.messagebox.show(ex.message); } } private void param1toolstriplabel_click(object sender, eventargs e) { } private void straattoolstripbutton_click(object sender, eventargs e) { try { this.fietsdiefstaltableadapter.straat(this.official_databasedataset.fietsdiefstal, param1toolstriptextbox1.text); } catch (system.exception ex) { system.windows.forms.messagebox.show(ex.message); } } } }
so, looks using fietsdiefstal
data both datagrid , chart.
you should make second data set aggregates results format desire. can in c# or in whatever language you're using fill data tables (i'm assuming sql?)
so, example, in sql query should like
select city, sum(somevalue) mytable group city
in city
column use populate x-axis , somevalue
bar height be.
if want in c#, want need loop on records. like:
var aggregatedata = new dictionary<string, int>(); foreach(datarow row in yourdatatable.rows) { int val; aggregatedata.trygetvalue(row["city"], out val); aggregatedata[row["city"]] = val + row["somevalue"]; }
(i have not tested these example)
Comments
Post a Comment