Simple Data Binding

To use simple data binding with a ShieldChart control, take the following steps in the following in the code-behind:

  • Set the DataSource property. This property points a data source such as a DataSet, DataTable, DataReader, ArrayList, etc.
  • Call the DataBind method on the first page load and after any data operation.

When using simple data-binding, you do not need to call the DataBind method when loading the page on postbacks; after postback ShieldChart uses the ViewState to recreate the data.

<shield:ShieldChart ID="ShieldChart1" runat="server">
    <PrimaryHeader Text="Internet usage statistics"></PrimaryHeader>
    <Axes>
        <shield:ChartAxisX 
            CategoricalValues="Jan, Feb, Mar, Apr, May, Jun"></shield:ChartAxisX>
        <shield:ChartAxisY>
            <Title Text="Visitor statistics"></Title>
        </shield:ChartAxisY>
    </Axes>
    <DataSeries>
        <shield:ChartBarSeries DataFieldY="Total" CollectionAlias="Total Visits">
        </shield:ChartBarSeries>
        <shield:ChartBarSeries DataFieldY="Unique" CollectionAlias="Unique Visits">
        </shield:ChartBarSeries>
    </DataSeries>
</shield:ShieldChart>
protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

    if (!Page.IsPostBack)
    {
        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;
        ShieldChart1.DataBind();
    }
}

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