New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

    SqlDataSource

    Year1996199719981999200020012002050001000015000200002500030000MWh5660.46452.89325.310201.413797.117772.925033.8Electricity Consumption

    This example shows how an ASP.NET AJAX Chart can be bound to an SqlDataSource. The major properties are:

    • DataSourceID in the main tag sets the declarative data source for the entire chart. The DataSource property can be used for a programmatic data source if you create the connection in the code-behind.
    • DataFieldY for the series to point it to the desired column of the data source.
    • DataLabelsField for the x-axis labels to populate the items for the axis (it can also be applied to the y-axis).
    • DefaultVB.aspx
    <%@ Page Language="vb"  %>
     
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html>
    <head runat="server">
        <title>Telerik ASP.NET Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
            SelectCommand="SELECT [Year], [Value] FROM [Data] WHERE ([Subcategory_Id] = 1)"></asp:SqlDataSource>
        <div class="demo-container size-wide">
            <telerik:RadHtmlChart runat="server" Width="800px" Height="500px" ID="RadHtmlChart1"
                DataSourceID="SqlDataSource1">
                <PlotArea>
                    <Series>
                        <telerik:ColumnSeries DataFieldY="Value" Name="Electricity Consumption">
                            <TooltipsAppearance Color="White" />
                        </telerik:ColumnSeries>
                    </Series>
                    <XAxis DataLabelsField="Year">
                        <LabelsAppearance RotationAngle="75">
                        </LabelsAppearance>
                        <TitleAppearance Text="Year">
                        </TitleAppearance>
                    </XAxis>
                    <YAxis>
                        <TitleAppearance Text="MWh">
                        </TitleAppearance>
                    </YAxis>
                </PlotArea>
                <Legend>
                    <Appearance Visible="false">
                    </Appearance>
                </Legend>
                <ChartTitle Text="Electricity Consumption">
                </ChartTitle>
            </telerik:RadHtmlChart>
        </div>
        </form>
    </body>
    </html>

    Support & Learning Resources

    Find Assistance