c# – 指定WPF图表的最小和最大轴

前端之家收集整理的这篇文章主要介绍了c# – 指定WPF图表的最小和最大轴前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是一个看似简单的问题,但我找不到简单的答案.我想在图表上指定现有Y轴的最小值和最大值.

这是图表:

<Window x:Class="TempDataAnalyzer.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" 
    xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
    Loaded="Window_Loaded">
<Grid>
     <chartingToolkit:Chart  Name="lineChart" Title="Temperature" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <chartingToolkit:LineSeries  DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="True"/>
     </chartingToolkit:Chart>
</Grid>

现在,我在Y轴上添加0到71之间的值:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Window_Loaded(object sender,RoutedEventArgs e)
    {
        List<KeyValuePair<int,int>> entries = new List<KeyValuePair<int,int>>();
        entries.Add(new KeyValuePair<int,int>(0,0));
        entries.Add(new KeyValuePair<int,int>(1,23));
        entries.Add(new KeyValuePair<int,int>(2,45));
        entries.Add(new KeyValuePair<int,int>(3,46));
        entries.Add(new KeyValuePair<int,int>(4,71));

        lineChart.DataContext = entries;
    }

}

但是,我希望图表Y轴显示0到100之间的范围,无论我添加什么值.这是为了使它与同一页面上的不同图表保持一致.

解决方法

在Chart声明中添加此XAML代码
<chartingToolkit:Chart.Axes>
    <chartingToolkit:LinearAxis Orientation="Y" Minimum="0" Maximum="100"/>
</chartingToolkit:Chart.Axes>
原文链接:https://www.f2er.com/csharp/91196.html

猜你在找的C#相关文章