Welcome to Pete Brown's 10rem.net

First time here? If you are a developer or are interested in Microsoft tools and technology, please consider subscribing to the latest posts.

You may also be interested in my blog archives, the articles section, or some of my lab projects such as the C64 emulator written in Silverlight.

(hide this)

Silverlight Toolkit (Silverlight 2 Control Pack) - Charting

Pete Brown - 28 October 2008

The Silverlight Toolkit is now available! Here’s a rundown of what’s included:

  • Chart
  • TreeView
  • AutoCompleteBox
  • DockPanel
  • WrapPanel
  • Label
  • Expander
  • HeaderedItemControl
  • HeaderedContentControl
  • NumericUpDown
  • ViewBox
  • ButtonSpinner
  • ImplicitStyleManager (Yay!)
  • Theming

All of this goodness is contained in just in three libraries all named Microsoft.Windows.Controls.*

Let’s dig into the charting in this first post. I’ll have some additional posts later covering styling of charts, and some of the more interesting bits of the other controls.

The charting example Xap that comes with the toolkit does a great job of showing off the different types of graphs and charts you can create. The screenshots are about a week or two out of date, but the November release is very similar.

image image image image image image

If you look at the controls, all you’ll see is <Chart>. You’ll probably find yourself wondering how on earth you use that to get pie and scatter and other types of charts.

The trick is the series:

  • ColumnSeries
  • DynamicSeries
  • DynamicSeriesWithAxes
  • DynamicSingleSeriesWithAxes
  • LineSeries
  • PieSeries
  • ScatterSeries

Let’s take PieSeries for an example. PieSeries has an ItemsSource courtesy of the inheritance from ->DynamicSeries->Series.

<UserControl x:Class="PeteBrown.SilverlightToolkitExamples.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"             
    xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"        
    xmlns:charts="clr-namespace:Microsoft.Windows.Controls.DataVisualization.Charting;assembly=Microsoft.Windows.Controls.DataVisualization"        
    Width="500" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <charts:Chart>
            <charts:Chart.Series>
                <charts:PieSeries>
                    <charts:PieSeries.ItemsSource>
                        <controls:ObjectCollection>
                            <sys:Double>1.0</sys:Double>
                            <sys:Double>2.0</sys:Double>
                            <sys:Double>0.5</sys:Double>
                            <sys:Double>0.3</sys:Double>
                            <sys:Double>1.2</sys:Double>
                            <sys:Double>1.8</sys:Double>
                        </controls:ObjectCollection>
                    </charts:PieSeries.ItemsSource>
                </charts:PieSeries>
            </charts:Chart.Series>
        </charts:Chart>
    </Grid>
</UserControl>

That Xaml creates a pie chart that (in the CTPs) looks like this:

image

To change it to a bar chart, I simply change the Series type to ColumnSeries:

            <charts:Chart.Series>
                <charts:ColumnSeries>
                    <charts:ColumnSeries.ItemsSource>
                        <controls:ObjectCollection>
                            <sys:Double>1.0</sys:Double>
                            <sys:Double>2.0</sys:Double>
                            <sys:Double>0.5</sys:Double>
                            <sys:Double>0.3</sys:Double>
                            <sys:Double>1.2</sys:Double>
                            <sys:Double>1.8</sys:Double>
                        </controls:ObjectCollection>
                    </charts:ColumnSeries.ItemsSource>
                </charts:ColumnSeries>
            </charts:Chart.Series>

and I get this:

image

I didn’t provide any labels or do any styling yet. Also, when you look at the markup in VS, you will see a blank chart due to the way the animation is set to fade in.

Note also that a designer can hard-code values into the chart at design time, allowing for rapid prototyping and for styling against something semi-real with zero code. You can load the itemsource from code, of course.

Back to the pie chart now. Let’s look at one of the more interesting style-related properties: AnimationSequence. That Series property provides options for FirstToLast, LastToFirst and Simultaneous.

<charts:PieSeries AnimationSequence="FirstToLast">

In the case of the default animation, it makes the individual items fade in in First-to-last order.

The remaining visual properties are those you’d expect to find on any control.

Shortly, I’ll put up a post about styling these controls and get a little more in-depth on the charting. Until then, explore and have fun with all the new goodies :)

You’ll find the full toolkit published on Codeplex here.

   
posted by Pete Brown on Tuesday, October 28, 2008
filed under:    

5 comments for “Silverlight Toolkit (Silverlight 2 Control Pack) - Charting”

  1. Pete Brownsays:
    @guest

    It's free information about controls that (at the time of this post's writing) were brand new to most of the Silverlight community. Deeper tutorials and examples have been released since then.

    If there's anything specific you're looking for, let me know :)

    Pete

Comment on this Post

Remember me

16 trackbacks for “Silverlight Toolkit (Silverlight 2 Control Pack) - Charting”

  1. Silverlight Toolkit (Silverlight 2 Control Pack) - Charting | Silverlight Guidesays:
    PingBack from http://www.silverlightguide.com/news/silverlight-toolkit-silverlight-2-control-pack-charting
  2. Boon Blogsays:
    Today, at PDC, the release of the Silverlight toolkit was made available.  Included in this release,
  3. Boon Blogsays:
    Today, at PDC, the release of the Silverlight toolkit was made available.  Included in this release,
  4. Community Blogssays:
    In this issue: Justin Angel, Ruurd Boerke, Jeff Wilcox, Pete Brown, and Tim Heuer. This is the 3rd post
  5. baggiojingsays:
    BarSeries Representsacontrolthatcontainsadataseriestoberenderedinbarformat. Col...
  6. baggiojingsays:
    BarSeries Representsacontrolthatcontainsadataseriestoberenderedinbarformat. Col...
  7. Delay's Blogsays:
    It's been nearly two weeks since the Silverlight Toolkit's November release . I've been trying to keep
  8. Delay's Blogsays:
    It's been a couple of months since I shared my semi-comprehensive page of Charting resources on the web
  9. Microsoft Weblogssays:
    It's been a couple of months since I shared my semi-comprehensive page of Charting resources on the web
  10. Felix Wang | Evangelizing the Next Websays:
    Overviews ( 100 level ) Silverlight Toolkit Released – More controls! - Tim Heuer 's during the PDC keynote
  11. DotNetClub Complutense Madridsays:
    En el blog de Felix Wang , he encontrado este artículo donde se agrupan una colección de
  12. Delay's Blogsays:
    It's been a while since the March 09 release of the Silverlight Toolkit - and even longer since I last
  13. Microsoft Weblogssays:
    It's been a while since the March 09 release of the Silverlight Toolkit - and even longer since I last
  14. Microsoft Weblogssays:
    In the time since posting my last collection of Silverlight/WPF Charting links , there's been some great
  15. Microsoft Weblogssays:
    In the time since sharing my last collection of Silverlight/WPF Charting links , there have been some
  16. Microsoft Weblogssays:
    In the time since sharing my last collection of Silverlight/WPF Charting links , there have been some