Telerik blogs

In the past year we put conscious effort into enhancing the data visualization components offered in Telerik’s control suite for ASP.NET AJAX development and we thought it was about time we started showcasing them in the Sales Dashboard sample application.

Since this was an interesting experience some of you might also be going through, we decided to share our know-how. This blog post is going to walk you through the 3 steps it takes to migrate from the existing charting component in the Sales Dashboard demo to HTML5 data visualization.     

The application at hand and the plan

The Sales Dashboard sample application has been around for quite a while and has always been showcasing that using together Telerik RadControls even from different technologies could bring great user experience with little effort. The application uses Northwind data to visually present sale representatives and how well they are performing. You could go through detailed information on the orders, sales in different years and the countries that orders have been made for each individual representative.
Sales Dashboard Application

Step #1: Remove the code of the original charting component and all dependencies

Go to your solution and delete all assemblies and references in the solution explorer to the old chart, because you won’t need them anymore.

The next step is removing the code that initialized and loaded the Silverlight application on the page. In our case it is just 13 lines of code.

Step #2: Define RadHtmlChart controls and set their styles

The fun comes when you start playing with Telerik’s HTML5-based ASP.NET Chart control, RadHtmlChart. The component features rich functionality and could be styled easily the same way as the RadChart. The definition for the required DonutSeries is just couple of lines which utilizes client templates, data formatting and appearance settings.

 

Take a quick look at the code to get a general idea of how little it takes to achieve such rich user experience.

<telerik:RadHtmlChart ID="RadHtmlChartTotalOrders" runat="server" Width="290px" Height="350px" CssClass="totalOrdersChart">
    <Appearance>
        <FillStyle BackgroundColor="Black" />
    </Appearance>
    <ChartTitle Text="Total Sales for Representative">
        <Appearance Align="Center" BackgroundColor="Black" Position="Top">
        </Appearance>
    </ChartTitle>
    <Legend>
        <Appearance Visible="false">
        </Appearance>
    </Legend>
    <PlotArea>
        <Series>
            <telerik:DonutSeries HoleSize="30">
                <LabelsAppearance DataFormatString="{0} %">
                    <TextStyle Color="Black" />
                </LabelsAppearance>
                <TooltipsAppearance ClientTemplate="#= category #"></TooltipsAppearance>
            </telerik:DonutSeries>
        </Series>
    </PlotArea>
</telerik:RadHtmlChart>

 

Step #3: DataBind using existing database data

Binding RadHtmlChart is very specific to each individual case. However, looking at the code below it is easy to notice how convenient and simple the chart programmatic creation is. And that is not all. The data visualization view packs both RadHtmlChart and RadGauge. The one liner at the end of the code snippet below shows how to set the value of Telerik’s ASP.NET Gauge control.

var employeesTotalOrders = this.Service.GetEmployeesTotalOrders(this.StartDate, this.EndDate);
double sum = employeesTotalOrders.Sum(i => i.Value);
foreach (var result in employeesTotalOrders)
{
    SeriesItem item = new SeriesItem();
    item.YValue = (decimal)((int)((result.Value / sum) * 100));
    item.Name = string.Format("Rep Name: {0}<br/>Sales amount:{1:C0}<br/>Percent sales:{2} %",
        result.Key,
        result.Value,
        item.YValue);
    this.RadHtmlChartTotalOrders.PlotArea.Series[0].Items.Add(item);
}
this.RadRadialGauge1.Pointer.Value = (decimal)this.Service.GetEmployeeQuarterTotalOrders(this.Employee, this.EndDate);

Benefits

With these three easy steps we have been able to utilize the latest and greatest HTML Charts for ASP.NET by taking advantage of the fast performance and small HTML footprint resulting in great end user experience.  It’s always best if you see it for yourself so go to the Sales Dashboard application in the link here and take a look at the performance of the charts and what that brings to the user experience.

It’s your turn

Migrating existing charting applications or creating a brand new data visualization solution from scratch is made easy with the help of Telerik’s HtmlChart and Gauge controls. Check out the cool demos and if you have any questions do not hesitate to contact our support team.

Telerik ASP.Net AJAX Controls - Download a trial version

About the Author

Antonio Stoilkov

is passionate about sports and loves to learn new things regardless if it is about the next quantum computer advancement or a new keyboard shortcut.

Related Posts

Comments

Comments are disabled in preview mode.