这是一个看似简单的问题,但我找不到简单的答案。我想为图表上现有的 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 之间的范围。这是为了使其与同一页面上的不同图表保持一致。