ASE Home Page Products Download Purchase Support About ASE
ChartDirector General
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Partial Update of dynamically created WebChartViewer
Posted by Mari on Sep-23-2016 23:48
Hi,

I am new in using WebChartViewer features.
So I wonder to know is there any way to update dynamically created WebChartViewer(Asp.Net Web Forms)?

For example I create some Bar Chart like this:

  WebChartViewer viewer = new WebChartViewer();
  viewer.ID = "testViewer";

I am able to draw this chart on the page like png image and everything seems to work good here, but how to update it?

For charts created in Web Forms I saw next code:
<chart:WebChartViewer id="WebChartViewer1" runat="server"/>

if (WebChartViewer.IsPartialUpdateRequest(Page)) {

        WebChartViewer1.LoadViewerState();

        drawChart(WebChartViewer1);

        WebChartViewer1.PartialUpdateChart();
    }

Is there any similar functionality for dynamically created charts?

  Re: Partial Update of dynamically created WebChartViewer
Posted by Peter Kwan on Sep-24-2016 01:59
Hi Mari,

The code can be the same for dynamically generated WebChartViewer. For example:

private WebChartViewer WebChartViewer1;

protected void Page_Load(object sender, EventArgs e)
{
    // Dynamically generated a WebChartViewer and put it in an ASP.NET Panel
    WebChartViewer1 = new WebChartViewer();
    WebChartViewer1.ID = "chart1";
    Panel1.Controls.Add(WebChartViewer1);

    if (WebChartViewer.IsPartialUpdateRequest(Page)) {
        WebChartViewer1.LoadViewerState();
        drawChart(WebChartViewer1);
        WebChartViewer1.PartialUpdateChart();
    }
}

One common usage of dynamically generated controls is that the code may generate a variable number of controls. This also works for the WebChartViewer control. However, when handling the zooming and scrolling, you would need to determine which WebChartViewer control is requesting the zooming and scrolling and handle it appropriately. The structure to handle the partial request will be like:

    if (WebChartViewer.IsPartialUpdateRequest(Page)) {
        // Get the clientId of the control that triggers the partial update request
        string clientId = WebChartViewer.GetSenderClientId();

        WebChartViewer myControl = .... dynamically create that control .....;

        myControl .LoadViewerState();
        drawChart(myControl);
        myControl.PartialUpdateChart();
    }

Hope this can help.

Regards
Peter Kwan