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

ClientDataSource

This example shows how a RadHtmlChart control can be bound to RadClienDataSource. The RadClientDataSource instance retreieves the data stored in a json file and orderes the data items by the year property in asc order. The significant chart properties are:

  • ClientDataSourceID in the main tag sets the declarative client data source for the entire chart.
  • 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
  • DefaultVB.aspx.vb
  • spain-electricity.json
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="DefaultVB.aspx.vb" Inherits="Telerik.Web.Examples.HtmlChart.ClientDataSource.DefaultVB" %>

<%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<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" />
    <div class="demo-container size-wide">
        <telerik:RadClientDataSource ID="ClientDataSource1" runat="server">
            <SortExpressions>
                <telerik:ClientDataSourceSortExpression FieldName="year" SortOrder="Asc" />
            </SortExpressions>
            <DataSource>
                <WebServiceDataSourceSettings ServiceType="GeoJSON">
                    <Select Url="spain-electricity.json" DataType="JSON" ContentType="application/json" />
                </WebServiceDataSourceSettings>
            </DataSource>
        </telerik:RadClientDataSource>

        <telerik:RadHtmlChart runat="server" ID="RadHtmlChart1" Width="100%" ClientDataSourceID="ClientDataSource1">
            <ChartTitle Text="Spain electricity production (GWh)"></ChartTitle>
            <Legend>
                <Appearance Position="Top"></Appearance>
            </Legend>
            <PlotArea>
                <Series>
                    <telerik:LineSeries DataFieldY="nuclear" Name="Nuclear">
                        <LabelsAppearance Visible="false"></LabelsAppearance>
                    </telerik:LineSeries>
                    <telerik:LineSeries DataFieldY="hydro" Name="Hydro">
                        <LabelsAppearance Visible="false"></LabelsAppearance>
                    </telerik:LineSeries>
                    <telerik:LineSeries DataFieldY="wind" Name="Wind">
                        <LabelsAppearance Visible="false"></LabelsAppearance>
                    </telerik:LineSeries>
                </Series>
                <XAxis DataLabelsField="year">
                    <LabelsAppearance RotationAngle="-90"></LabelsAppearance>
                </XAxis>
                <YAxis Step="10000"></YAxis>
                <CommonTooltipsAppearance Shared="true" Visible="true"></CommonTooltipsAppearance>
            </PlotArea>
        </telerik:RadHtmlChart>
    </div>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance