Last post Dec 15, 2016 12:27 PM by ademarr
Dec 08, 2016 08:23 PM|RedDragonX|LINK
It is *very* likely that I am just going about this all wrong, and that this is not an issue at all...
I have 6 charts on a page, and I am binding them on page load. When I drill down into one of them, it causes a postback on the page and all charts get reset to their initial binding
Is there a way to have each chart retain their data even while I am causing a postback by clicking on another chart?
Dec 08, 2016 08:29 PM|codemovement.pk|LINK
Is the problem that after a postback the charts isn't what was generatd on the page load? There is a setting on the chart called EnableViewState you could try setting that to
<asp:Panel runat="server" ID="PanelRight" CssClass="roadmapRight">
<asp:Chart ID="ChartRemainingDaysHistory" runat="server" EnableViewState="true">
<AxisY Title="Days Remaining" />
<AxisX Title="Date" IsLabelAutoFit="True">
<LabelStyle Angle="90" Interval="2" />
Dec 08, 2016 08:40 PM|RedDragonX|LINK
The problem is that if I was to drill down on one of the charts, then try to click on a different chart, the first one will revert to its initial image.
on Page_Load I am binding all of these charts. If I click on an X Value on a chart I generate a new SQL Query and re Bind the chart. When I bind the chart again, it causes all of the charts (except the one that I am currently binding) to be reloaded based
on the queries that were written in Page_Load.
P.S. I tried EnabledViewState, but that didn't work.
Dec 08, 2016 08:47 PM|codemovement.pk|LINK
Dec 09, 2016 07:45 AM|Cathy Zou|LINK
From your description, I suggest you could bind chart only when the page first load.
Something like this:
protected void Page_Load(object sender, EventArgs e)
//bind your chart here
Dec 09, 2016 02:54 PM|RedDragonX|LINK
That was my first attempt to fix this issue... binding the charts only on the first load has worse effects on the charts. The first load, they all bind properly... but then if I click on one of the charts, all 5 of the other charts lose their images. Maybe
I am setting it up in a bad way to begin with ?
private void PopulateChart(string queryString, Chart chart, string chartArea, string strSeries)
using (SqlConnection con = new SqlConnection(cs))
SqlCommand cmd = new SqlCommand(queryString, con);
SqlDataReader rdr = cmd.ExecuteReader();
chart.DataSource = rdr;
chart.Series[strSeries].ChartArea = chartArea;
chart.Series[strSeries].IsValueShownAsLabel = true;
chart.ChartAreas[chartArea].AxisX.MajorGrid.Enabled = false;
chart.Series.PostBackValue = "#VALX";
that is the function that I am using to populate the data. Then I have a Chart_Click function where I create a new query and re-bind the chart.
So I have 2 adverse possibilities at the moment. either I bind my charts on Page_Load, and after my Chart_Click event fires all of my charts (except the one I clicked on) revert back to their Page_Load states ... or I bind my charts only on !PostBack and
then after my Chart_Click event is fired all of my charts (except the one I clicked on) go blank.
Dec 12, 2016 07:02 PM|RedDragonX|LINK
Thanks for the help you two ... I figured out what my issue was, and its possible I wasn't being clear with my description of the issue. So in case anyone else stumbles on this post with the same issue, I fixed it by simply setting EnableViewState to True
for each of my charts. Now they keep the data from the drilldown even when the page does a postback!
Dec 15, 2016 12:27 PM|ademarr|LINK
Yes... #Cathy_Zou You're Right.