Sunday, July 19, 2009

Pie Chart in Silverlight with WCF - (Part 2 of Many)

Implementation:

Open Microsoft Visual Studio 2008, go to FILE MENU and select CREATE\NEW PROJECT. Select “SilverlightApplication” on the right and make sure you window looks like below. And also make sure all the highlted fields are same and you can give any name to the project , but as we are doing a Pie Chart I named it as PieChart.



Click on OK to start working on our project. As Silverlight is a Client side application, it needs a host to run on the web browser. And below is the window how it looks (I am using Silverlight 3.0)



Make sure you have a good look at the highlighted fields, it will tell you that you need a server side host, like a web application to host the silverlight.
Points to be noticed:
1. Silverlight is a Client side application
2. It needs a server side application(like a web browser) to host the application
Click on OK to start your project.

As we selected the check box in the previous window to host our silverlight application it creates a new PieChart.Web project to our project we just created and below is how it looks in the solution explorer window and also gives us some sample code with the default namespaces and references.


The selected “PieChart.Web” is the host project that is created by Visual Studio to host our Silverlight application. And the PieChartTestPage.aspx is the file that is used to show in the browser.
And MainPage.xaml is the file that is where we do the programming for our PieChart, which is coded in XAML language. So let us just keep the “Piechart.Web” aside for a while and let’s work on MainPage.xaml.
Before we design out Pie Chart we need some data to show in the Pie chart. To draw any Pie chart we need two sets of values one set will be words and the second set will be numbers to relate the text. In Silverlight these set of values are denoted as “IndependentValueBinding” for the set of text and “DependentValueBinding” for the values set. So Lets give the data first in our database (SQL Server), Lets open SQL Sever Management Studio to create a database called “Expences” with a table called “ExpensesTable” with two attributes, Months(for IndependentValueBinding) and Expences (for DependentValueBinding).

Please see this post to create a database in SQLServer “Database Creation” (Caution: only for first timers).

As this post is for Silverlight, we are not discussing SQL Server and creating Tables in SQL Server. For any reference please see the post mentioned above.

Once you are done with creating Database and a Table, lets jump into Visual Studio to use the data for our PieChart.

Note: Silverlight is so fun to play with various builtin controls and animations etc, but when it comes to data binding and using data in our silverlight application we need a web service for the Silverlight Application to invoke data from the database.
The reason behind this is, as we know that Silverlight is a client side application and the data will always be on the server side, so we need a web service to read the server side data in our application.

Next Part Continues...
To See all parts for Pie Chart in Silverlight with WCF, please click on the link to the right that says it.
You can download the final version of the project and final version of the post in a word document in the final part of this post.
Please do comment or leave any suggestions or questions below, I will reply immediately. You may also leave any requests for new posts.

No comments:

Post a Comment