C# Windows Form Chart control - binding multiple y values from csv file -


this first exposure data-binding, have little knowledge of of properties , methods involved. want bind multiple series csv file column 1 datetime, , columns 2 through n doubles. started example in winformschartsamples binding single y value csv; however, not believe understanding way bind multiple y values.

the original code:

string myselectquery = "select * " + file; string constr = "provider=microsoft.jet.oledb.4.0;data source=" + path + ";extended properties=\"text;hdr=no;fmt=delimited\"";  oledbconnection myconnection = new oledbconnection(constr);  // create database command on connection using query oledbcommand mycommand = new oledbcommand(myselectquery, myconnection);  // open connection mycommand.connection.open();  // create database reader oledbdatareader myreader = mycommand.executereader(commandbehavior.closeconnection);  // column 1 time value, column 2 double // databind reader chart using databindxy method chart1.series[0].points.databindxy(myreader, "1", myreader, "2"); 

the following works:

mycommand.connection.open(); oledbdatareader myreader = mycommand.executereader(commandbehavior.closeconnection); chart1.series[0].points.databindxy(myreader, "1", myreader, "2");  mycommand.connection.open(); myreader = mycommand.executereader(commandbehavior.closeconnection); chart1.series[1].points.databindxy(myreader, "1", myreader, "3");  mycommand.connection.open(); myreader = mycommand.executereader(commandbehavior.closeconnection); chart1.series[2].points.databindxy(myreader, "1", myreader, "4"); 

i put above loop , iterate on of series, surely there better way reading through csv file multiple times?

turns out did find better way:

string myselectquery = "select * " + file; string constr = "provider=microsoft.jet.oledb.4.0;data source=" + path + ";extended properties=\"text;hdr=no;fmt=delimited\"";  oledbconnection myconnection = new oledbconnection(constr); oledbcommand mycommand = new oledbcommand(myselectquery, myconnection);  chart1.datasource = mycommand;  (int = 0; < chart1.series.count; i++) {     chart1.series[i].xvaluemember = "1";     chart1.series[i].yvaluemembers = (i+2).tostring(); } chart1.databind();  

perhaps else...


Comments

Popular posts from this blog

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

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -