|
Dynamically generate charts |
Posted by Gordon on Feb-09-2009 10:40 |
|
I have a database from which I want to generate on chart for each set of data, presented sequentially down the HTML page. Trouble is I do not know in advance how many sets will exist.
I can use code like
OracleConnection ocon = new OracleConnection(constr);
ocon.Open();
string sqlstr = "SELECT DISTINCT SYSTEM_NAME FROM MYSYSTEMDATA_V";
OracleDataAdapter oda = new OracleDataAdapter(sqlstr, ocon);
oda.Fill(systemnames);
foreach (DataRow systemrows in systemnames.Tables[0].Rows)
{
string sname = systemrows.ItemArray[0].ToString();
Is there a simple way to dyamically create a different chart for each sname. |
Re: Dynamically generate charts |
Posted by Peter Kwan on Feb-09-2009 11:40 |
|
Hi Gordon,
You do not need to know in advance the number of data sets you have. You can just create the charts dynamically, just like creating any other controls dynamically in your web page.
foreach (DataRow systemrows in systemnames.Tables[0].Rows)
{
.... Get the data from your sname ....
XYChart c = new XYChart(.......);
.... create chart as usual .....
//dynamically add a WebChartViewer
WebChartViewer w = New WebChartViewer();
//myContainer is the container which determines the position you want to
//insert the WebChartViewer in the web page
myContainer.Add(w);
}
If your web page does not have any WebChartViewer, other than the ones dynamically created, you would need to add the following line as the first line of Page_Init:
//for C#
WebChartViewer.OnPageInit(this);
(You may look for "OnPageInit" in the ChartDirector documentation index to see why the above line is needed.)
Hope this can help.
Regards
Peter Kwan |
|