Specify the minimum and maximum axes for the WPF chart

This would seem to be a simple question, but I cannot find a simple answer. I want to specify the minimum and maximum for the existing Y axis in the chart.

Here's the chart:

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

Now I add values ​​from 0 to 71 along the Y axis:

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

However, I want the Y axis of the graph to show me a range from 0 to 100, no matter what values ​​I add. This means that it is compatible with different charts on the same page.

enter image description here

+6
source share
1 answer

Add this XAML code inside the Chart declaration:

 <chartingToolkit:Chart.Axes> <chartingToolkit:LinearAxis Orientation="Y" Minimum="0" Maximum="100"/> </chartingToolkit:Chart.Axes> 
+9
source

All Articles