How to Bind points on to the wpf Area chart using generic list databinding
in wpf
I am working on WPF using c#. I am trying to display WPF Area chart with
values using WPF Toolkit. I have followed the CodeProject's KB Article and
write it like,
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" x:Class="WpfChart.MainWindow"
Title="MainWindow" Height="621.053" Width="873.684">
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" Margin="0,-28,0,28">
<Grid Height="921">
<DVC:Chart x:Name="areaChart" Title="Chart Title"
VerticalAlignment="Top" Margin="33,73,24,0" Height="582"
Background="White" >
<DVC:AreaSeries DependentValuePath="Value"
IndependentValuePath="Key" ItemsSource="{Binding}"
IsSelectionEnabled="True" Title="Weeks of
Gestation"></DVC:AreaSeries>
<DVC:Chart.Palette>
<DV:ResourceDictionaryCollection>
<ResourceDictionary>
<Style x:Key="DataPointStyle"
TargetType="Control">
<Setter Property="Background"
Value="Firebrick" />
<Setter Property="BorderBrush"
Value="Black" />
</Style>
</ResourceDictionary>
</DV:ResourceDictionaryCollection>
</DVC:Chart.Palette>
<DVC:Chart.Axes>
<!-- Add Horizontal and Vertical Axes-->
<DVC:LinearAxis ShowGridLines="True"
Orientation="Y"
Title="Y Axis Title"
Interval="5" Maximum="45" Minimum="-5"
Foreground="Black"
FontFamily="Arial Black"
FontSize="16"
FontWeight="Bold"
/>
<DVC:LinearAxis ShowGridLines="True"
Orientation="X"
Title="X-Axis Title"
Interval="4" Minimum="0" Maximum="40"
Foreground="Black"
FontFamily="Arial Black"
FontSize="16"
FontWeight="Bold"
/>
</DVC:Chart.Axes>
</DVC:Chart>
</Grid>
</ScrollViewer>
</Window>
and i write code for initialization chart data like,
private void LoadAreaChartData()
{
((AreaSeries)areaChart.Series[0]).ItemsSource =
new KeyValuePair<string, int>[]{
new KeyValuePair<string, int>("3", 5)
};
}
But it does not map the points on to the chart. I need to map the point on
to the chart like,
(X,Y)--(3,5) its need to mark at the intersection of point 3 on x-axis and
point 5 on y-axis. How can i achieve this please guide me if i went in the
wrong way. Thanks in advance.
No comments:
Post a Comment