Click here to Skip to main content
15,885,366 members
Articles / Desktop Programming / WPF

Simple WPF Bar Chart Control

Rate me:
Please Sign up or sign in to vote.
4.81/5 (23 votes)
3 Oct 2008CPOL4 min read 127.8K   4K   58  
This article presents step-by-step instructions on how to create a simple bar chart using WPF.
<UserControl x:Class="SimpleChart.Charts.BarChart"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     Height="640" Width="480">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.05*"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
            <Slider Name="zoomSlider" Grid.Row="0" Grid.Column="1" Height="20" DockPanel.Dock="Top" Minimum="1" Maximum="5" Value="1"/>
            <ScrollViewer Grid.Row="1" Grid.Column="1" CanContentScroll="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <Canvas  x:Name="chartArea" ClipToBounds="False" Background="Black">
                <Canvas.LayoutTransform>
                     <ScaleTransform ScaleX="{Binding ElementName=zoomSlider, Path=Value}"
                          ScaleY="{Binding ElementName=zoomSlider, Path=Value}"/>
                </Canvas.LayoutTransform>
                <TextBlock  x:Name="txtNoData" FontSize="12" Text="No data found." Visibility="Hidden"
                      Opacity="100" Foreground="Red">
                </TextBlock>
            </Canvas>
        </ScrollViewer>
    </Grid>
</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
Founder Algorisys Technologies Pvt. Ltd.
India India
Co Founder at Algorisys Technologies Pvt. Ltd.

http://algorisys.com/
https://teachyourselfcoding.com/ (free early access)
https://www.youtube.com/user/tekacademylabs/

Comments and Discussions