0

我正在使用 c# 处理 WPF。我正在尝试使用 WPF Toolkit 显示带有值的 WPF 面积图。我已经按照 CodeProject 的 KB 文章进行了编写,如下所示,

<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>

我为初始化图表数据编写代码,例如,

private void LoadAreaChartData()
        {

            ((AreaSeries)areaChart.Series[0]).ItemsSource =
                new KeyValuePair<string, int>[]{
    new KeyValuePair<string, int>("3", 5)
    };
        }

但它不会将点映射到图表上。我需要将点映射到图表上,例如,

(X,Y)--(3,5) 需要在x轴的3点和y轴的5点的交点上做标记。如果我走错了路,我怎么能做到这一点,请指导我。提前致谢。

4

0 回答 0