MSChart State Management


MSChart have a problem of maintaining data state during post back. When a post back happens the Chart will get blank or data get cleared.

Typically charts are used to provide a presentation of data in graphical manner. How can we make the chart object persist its data during post back? There are couple of ways:

1. By using the chart ViewState, but ViewState have its own problems.

Before enabling ViewState

MSChart1.gif

After enabling ViewState

<asp:Chart ID="Chart1" runat="server" EnableViewState="true">

MSChart2.gif

You can see the difference in bytes size.

2. By again re-populate the chart with data from database. On every post back we need to use this.

3. Or save the dataset/datatable and later use for rebinding.

4. Another efficient way is by saving the Chart into a file. It can be binary or xml.

By using Charting SerializationFormat, refer msdn URL for more information.

http://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.serializationformat.aspx

Sample code attached, Please post your responses.

Up Next
    Ebook Download
    View all
    Learn
    View all