Advanced Data Binding

The key to the advanced data binding of a ShieldChart control is handling the TakeDataSource event. ShieldChart fires the TakeDataSource event each time it needs to be bound to a data source. If, at the time of the event, the DataSource property is not set to a valid data source object, the chart will not behave correctly.
The TakeDataSource event fires in the following cases:

  • Immediately after On_Load if the chart has not yet been data-bound.
  • When a call to the chart’s DataBind() method takes place.

For performance reasons the TakeDataSource event is not fired on regular postbacks. In this case the data for all series are kept into the ViewState of the component.
Important: You should never call the DataBind() method in a TakeDataSource event handler event.
NOTE that when EnableViewState is set to False, the chart will fire TakeDataSource and will bind each time the page loads, not only the first time.

<shield:ShieldChart ID="ShieldChart1" Width="100%" Height="400px" runat="server" 
    OnTakeDataSource="ShieldChart1_TakeDataSource" IsInverted="true"
    <PrimaryHeader Text="Internet usage statistics"></PrimaryHeader>
            CategoricalValues="Jan, Feb, Mar, Apr, May, Jun"></shield:ChartAxisX>
            <Title Text="Visitor statistics"></Title>
        <shield:ChartBarSeries DataFieldY="Total" CollectionAlias="Total Visits">
        <shield:ChartBarSeries DataFieldY="Unique" CollectionAlias="Unique Visits">
protected void ShieldChart1_TakeDataSource(object sender, Shield.Web.UI.ChartTakeDataSourceEventArgs e)
    List datasource = new List() 
        new VisitorStatistic() { Total = 565000, Unique = 152000 },
        new VisitorStatistic() { Total = 630400, Unique = 234000 },
        new VisitorStatistic() { Total = 743000, Unique = 123000 },
        new VisitorStatistic() { Total = 910200, Unique = 348000 },
        new VisitorStatistic() { Total = 1170200, Unique = 167000 },
        new VisitorStatistic() { Total = 1383000, Unique = 283000 }

    ShieldChart1.DataSource = datasource;

private class VisitorStatistic
    public double Unique { get; set; }
    public double Total { get; set; }