如何在WPF中添加chart控件,绘制X,Y轴及动态曲线
发布网友
发布时间:2022-04-30 04:07
我来回答
共1个回答
热心网友
时间:2023-10-11 08:53
我们可以使用Toolkit Chart 控件去绘制图形
添加System.Windows.Controls.DataVisualization.Toolkit.dll 引用后,XAML中可以以下面的方式使用
<Window x:Class="WpfChart3._5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:datavis="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
Title="MainWindow" Height="350" Width="525">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10" Grid.Column="1" Grid.Row="0">
<charting:Chart x:Name="waitingtasks" BorderBrush="Transparent" BorderThickness="0" VerticalAlignment="Stretch" Title="Waiting Tasks">
<charting:Chart.TitleStyle>
<Style TargetType="datavis:Title">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Foreground" Value="White"/>
</Style>
</charting:Chart.TitleStyle>
<charting:Chart.LegendStyle>
<Style TargetType="datavis:Legend">
<Setter Property="Width" Value="0" />
</Style>
</charting:Chart.LegendStyle>
<charting:Chart.Axes>
<charting:LinearAxis Orientation="X" Title="Time" Interval="20" ShowGridLines="False"/>
<charting:LinearAxis Title="Number of Waiting Tasks" Orientation="Y" Interval="5" ShowGridLines="False"/>
</charting:Chart.Axes>
<charting:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True"
AnimationSequence="FirstToLast"/>
</charting:Chart>
</Grid>
</Window>