locked
Mulitple Charts on page - all refresh image on postback RRS feed

  • Question

  • User2009701734 posted

    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?

    Thursday, December 8, 2016 8:23 PM

Answers

  • User2009701734 posted

    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!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 12, 2016 7:02 PM

All replies

  • User-691209617 posted

    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 true

    <asp:Panel runat="server" ID="PanelRight" CssClass="roadmapRight">
        <asp:Chart ID="ChartRemainingDaysHistory" runat="server" EnableViewState="true">
            <Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartAreaLineGraph">
                    <AxisY Title="Days Remaining" />
                    <AxisX Title="Date" IsLabelAutoFit="True">
                        <LabelStyle Angle="90" Interval="2" />
                    </AxisX>
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
    </asp:Panel>

    Thursday, December 8, 2016 8:29 PM
  • User2009701734 posted

    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.

    Thursday, December 8, 2016 8:40 PM
  • User-691209617 posted

    check this answer

    Thursday, December 8, 2016 8:47 PM
  • User-707554951 posted

    Hi RedDragonX,

    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)
            {
              if (!IsPostBack)
                {
                    //bind your chart here
                }
             }

    Best regards

    Cathy

    Friday, December 9, 2016 7:45 AM
  • User2009701734 posted

    Cathy,

    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);
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                chart.DataSource = rdr;
                chart.DataBind();
                con.Close();
                chart.Series[strSeries].ChartArea = chartArea;
                chart.Series[strSeries].IsValueShownAsLabel = true;
                chart.ChartAreas[chartArea].AxisX.MajorGrid.Enabled = false;
                
            }
            chart.Series[0].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.

    Friday, December 9, 2016 2:54 PM
  • User2009701734 posted

    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!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 12, 2016 7:02 PM
  • User-1829366331 posted

    Yes... #Cathy_Zou You're Right.

    Thursday, December 15, 2016 12:27 PM