|
Multiple Stack Chart Based on Date Range |
Posted by Al on Jan-07-2011 01:34 |
|
I need to dynamically create multiple charts based on a date range, which could be from 2 to 10 dates. I need to create a chart for each date in the date range and the charts will all be on the same webpage (ASP.NET C#). I am using and XYChart chart with stacks. Can you point me in the right direction or provide some code sample? |
Re: Multiple Stack Chart Based on Date Range |
Posted by Peter Kwan on Jan-08-2011 00:57 |
|
Hi Al,
The WebChartViewer control is similar to any other control. You may use the standard methods to "dynamically create multiple controls" in a ASP.NET web page.
For example, you may:
(a) Put 10 WebChartViewer controls on your ASP.NET web page, and initialize them to all invisible (set the Visible property to false). Then you may use a loop to iterate through your dates, and create charts, and enable the WebChartViewer controls to display the charts.
or
(b) Simply use a loop to dynamically create charts and WebChartViewer controls (just create new WebChartViewer objects and add it to the container in your web page). Note that if you create the controls later than PageInit (eg. your code does not create the controls until PageLoad), the controls will not see the PageInit event (as they have not been created yet). In this case, you would need to put the line "ChartDirector.WebChartViewer.OnPageInit(this);" in the PageInit event handler of the WebForm to allow ChartDirector to see the PageInit event.
Hope this can help.
Regards
Peter Kwan |
Re: Multiple Stack Chart Based on Date Range |
Posted by Al on Feb-22-2011 21:13 |
|
Do you have exmaples of both methods? |
Re: Multiple Stack Chart Based on Date Range |
Posted by Al on Feb-23-2011 02:37 |
|
Do you have sample code? |
Re: Multiple Stack Chart Based on Date Range |
Posted by Peter Kwan on Feb-23-2011 10:41 |
|
Hi Al,
There are many sample code in ChartDirector that shows multiple charts per page. You just need to change it to a loop.
For example, in the "2D Pie Chart" sample code, the original code is:
createChart(WebChartViewer0, "0");
createChart(WebChartViewer1, "1");
createChart(WebChartViewer2, "2");
createChart(WebChartViewer3, "3");
createChart(WebChartViewer4, "4");
createChart(WebChartViewer5, "5");
You can change it to:
WebChartViewer[] viewers = {WebChartViewer0, WebChartViewer1, WebChartViewer2, WebChartViewer3, WebChartViewer4, WebChartViewer5};
//assume you draw 4 charts
int noOfCharts = 4;
for (int i = 0; i < noOfCharts; ++i) {
WebChartViewer[i].Visible = true;
createChart(WebChartViewer[i], i.ToString());
}
//set the order controls to invisible
for (int i = noOfCharts; i < WebChartViewer.Length; ++i)
WebChartViewer[i].Visible = false;
Hope this can help.
Regards
Peter Kwan |
Re: Multiple Stack Chart Based on Date Range |
Posted by Al on Mar-02-2011 20:53 |
|
Do you have a sample of using a loop to dynamically create charts and WebChartViewer controls? I need to create them dynamically.
For example I dnot watn to to this:
Put 10 WebChartViewer controls on your ASP.NET web page, and initialize them to all invisible (set the Visible property to false). Then you may use a loop to iterate through your dates, and create charts, and enable the WebChartViewer controls to display the charts.
I want to do it like this:
Simply use a loop to dynamically create charts and WebChartViewer controls (just create new WebChartViewer objects and add it to the container in your web page). Note that if you create the controls later than PageInit (eg. your code does not create the controls until PageLoad), the controls will not see the PageInit event (as they have not been created yet). In this case, you would need to put the line "ChartDirector.WebChartViewer.OnPageInit(this);" in the PageInit event handler of the WebForm to allow ChartDirector to see the PageInit event. |
Re: Multiple Stack Chart Based on Date Range |
Posted by Peter Kwan on Mar-03-2011 00:10 |
|
Hi Al,
I have attached an example based on the "Bar Gap" sample code. It just directly performs exactly what you mentioned:
Simply use a loop to dynamically create charts and WebChartViewer controls (just create new WebChartViewer objects and add it to the container in your web page). Note that if you create the controls later than PageInit (eg. your code does not create the controls until PageLoad), the controls will not see the PageInit event (as they have not been created yet). In this case, you would need to put the line "ChartDirector.WebChartViewer.OnPageInit(this);" in the PageInit event handler of the WebForm to allow ChartDirector to see the PageInit event.
Hope this can help.
Regards
Peter Kwan
|
Re: Multiple Stack Chart Based on Date Range |
Posted by Karthick raj on Jul-30-2013 15:36 |
|
Exactly The code working fine.Event Page_Init is not required..
How we adding the controls in the panel in code behind as the same way we do for adding
dynamic graph area.
Thanks and regards,
Karthick. |
Re: Multiple Stack Chart Based on Date Range |
Posted by Peter Kwan on Jul-31-2013 00:41 |
|
Hi Karthick,
To move the code to code-behind, just copy the code to the corresponding functions in your code behind module.
(a) Please create the Page.OnLoad event handler and Page.OnInit event handler using Visual Studio.
*** NOTE ***: Make sure you use Visual Studio to create the handlers declaration. If you copy copy the handler declaration yourself, you would also need to wire the handler to the event with your own code. If you are not sure how to do this, please use Visual Studit to create the event handlers for you.
(b) Copy the code in Page_Load to the Page.OnLoad event handler created by Visual Studio. Copy the code in Page_Init ot the Page.OnInit event handler created by Visual Studio. You may also need to add the line "using ChartDirector;" to import the namespace. Copy the entire "createChart" method (with the declaration and code) to your code-behind module.
Hope this can help.
Regards
Peter Kwan |
|