Click here to Skip to main content
15,887,485 members
Articles / Programming Languages / C#

Visualizing Live and Historic Stock Data Using Silverlight

Rate me:
Please Sign up or sign in to vote.
4.89/5 (12 votes)
19 Jan 2011CPOL13 min read 80.8K   2.9K   56  
The article aims to present a generic approach of fetching and visualizing live and historical stock data in Silverlight.
<UserControl x:Class="StockVisualization.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:charts="clr-namespace:Visiblox.Charts;assembly=Visiblox.Charts"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <StackPanel x:Name="LayoutRoot" Orientation="Vertical">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <TextBlock>Stock code:</TextBlock>
            <ComboBox x:Name="ComboStockCode">
                <ComboBoxItem Content="MSFT" IsSelected="True"/>
                <ComboBoxItem Content="GOOG"/>
                <ComboBoxItem Content="VOD"/>
                <ComboBoxItem Content="BCS"/>
            </ComboBox>
            <Button x:Name="BtnUpdate" Content="Update" Click="BtnUpdate_Click"/>
        </StackPanel>
        <StackPanel Orientation="Horizontal" x:Name="PanelFetchingData" Visibility="Collapsed" Margin="0,5,0,5" HorizontalAlignment="Center">
            <ProgressBar IsIndeterminate="True" Width="150" Height="15"/>
        </StackPanel>
        <charts:Chart x:Name="StockChart" Width="600" Height="300" LegendVisibility="Collapsed">
            <charts:Chart.Series>
                <!-- Add a LineSeries that shows points and displays tooltips when hovering over them -->
                <charts:LineSeries ShowPoints="True" ToolTipEnabled="True">
                    <charts:LineSeries.DataSeries>
                        <!-- Set the data source of the LineSeries to be a BindableDataSeries to allow binding to our business object collection -->
                        <charts:BindableDataSeries XValueBinding="{Binding Date}" YValueBinding="{Binding Price}"/>
                    </charts:LineSeries.DataSeries>
                </charts:LineSeries>
            </charts:Chart.Series>
            <charts:Chart.Behaviour>
                <charts:BehaviourManager AllowMultipleEnabled="True">
                    <charts:PanBehaviour YPanEnabled="False" IsEnabled="True"/>
                    <charts:ZoomBehaviour IsEnabled="True"/>
                  </charts:BehaviourManager>                
            </charts:Chart.Behaviour>
        </charts:Chart> 
        <TextBlock HorizontalAlignment="Center" Width="400" TextWrapping="Wrap" Text="Drag mouse to pan, scroll with mousewheel to zoom."/>
    </StackPanel>
</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United Kingdom United Kingdom
I am a WPF, Silverlight and Windows Phone developer. Visit my blog or follow me on Twitter @GergelyOrosz.

Comments and Discussions