ASP.NET 4 Chart Control


One of the best new feature of ASP.NET 4.0 Web Form (yes it’s still alive) is the new Chart control. There have been a need for a Chart control for a long time – from version 1.0. Folks have used custom controls from various sources or written their own one. Now in ASP.NET 4.0 Microsoft have introduced a Chart control ultimately. This could be used in ASP.NET MVC also apart from Web Forms.

The Chart control provides all different type of charts like Column, Bar, Line, Area, Pie, Doughnut (to name a few). Following is an example of Chart with chart type Column.

image

To set up a basic chart control you have to set a few properties like XValueMember and  YValueMembers. In the example I have displayed the Total Sales figure for few cities. Following is the page markup –

image

As you can see I’ve set XValueMemeber to City and YValueMembers to TotalSales – both of them are properties in my DTO –

image

The chart type could be set in markup or through code for the series –

image

chtSalesData.Series[“Series1”].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar;

image         image   

image         image

Web Browser Control in Silverlight 4


I have been playing with Silverlight 4 for a while now. I know it’s too late probably to talk about some of the new features of Silverlight 4 since Scott Gu already have announced Silverlight 5 to be made available in early 2011, but I have been rather quite busy with my day job Smile. Also I left Target India and joined Misys Software as Senior Architect – so as a whole on the professional front I have been little busy lately. Anyway, it never too late.

Among the many features included newly in Silverlight 4, max importance have been on enabling and adding features that would help use Silverlight for Business Application Development specially of Enterprise scale similar to other UI technologies like WPF, Win Forms (I know people are still using it for new enterprise business apps), ASP.NET Web Forms and ASP.NET MVC (both with and without Ajax).

Silverlight 4 now supports Web Browser control that was long present in Win Forms. The Web Browser control can load a HTML page – it’s truly a mini IE. Note that Web Browser control can show content only in Full Screen mode. When it’s running within a browser embedded it does not display any content –

image

Since Sliverlight 4 has started officially supporting Google Chrome (though earlier also it used to work) I thought of using Chrome for this post.

So to use Web Browser control, Silverlight 4 must have to run out of browser. To load a page/HTML content or any browsable content (that browser can interpret like ASP.NET web page), use the Source property of the Web Browser control –

<WebBrowser x:Name=”webBrowser” Source=”https://caniruddha.wordpress.com/” /> – XAML
webBrowser.Source = https://caniruddha.wordpress.com/; – code

You can also use the Navigate and NavigateToString methods. While Navigate accepts a sting for URL, NavigateToString accepts a Uri object –

webBrowser.Navigate(new Uri(“https://caniruddha.wordpress.com/”));
webBrowser.NavigateToString(https://caniruddha.wordpress.com/);

image