.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Chart Control in Silverlight - Part 1

Posted By:Mahadesh Mahalingappa       Posted Date: September 06, 2011    Points: 200    Category: Silverlight    URL: http://www.dotnetspark.com  

In this article we are going to see how we can use the Silverlight Chart Control to create Charts which are always the best way of data visualization.

We are going to see in a series of article how we use Silverlight Charts to visualise data in a exciting way.

In particular we are going to see a Column Series.

Before that lets do some database work.

create table Scorecard
  Batsman varchar(50),
 Runs int

insert into Scorecard values ('Sachin Tendulkar',0);
insert into Scorecard values ('Rahul Dravid',100);
insert into Scorecard values ('Virendar Sehwaj',10);

Create a Data Model as shown below :

Data Model in silverlight

Data Model Wizard in silverlight

silverlight Data Model

Create a Silverlight enabled service as shown below :

WCFservice in silverlight

public class DataService
    public IEnumerable GetScores()
        CricketDBEntities context = new CricketDBEntities();
        var query = from scorecard in context.Scorecards
                    select new Scores
                        Batsman = scorecard.Batsman,
                        Runs = scorecard.Runs
        return query;
    // Add more operations here and mark them with [OperationContract]

public class Scores
    public string Batsman { get; set; }
    public int? Runs { get; set; }

Modify the code of the Chart1.xaml to look as follows :


Add the Service reference and then modify the code behind of Chart1 as shown below :

public partial class Chart1 : UserControl
    public Chart1()
        //(this .chartControl.Series[ 0 ]).  =  users ; 

        DataServiceClient client = new DataServiceClient();
        client.GetScoresCompleted += new EventHandler(client_GetScoresCompleted);

    void client_GetScoresCompleted(object sender, GetScoresCompletedEventArgs e)
        ColumnSeries series0 = (ColumnSeries)chartControl.Series[0];
        series0.ItemsSource = e.Result;

Lets give this a run :

silverlight chart control

Great. Works..

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend