在这里,我给出了3和4的值,并在图中指出了该值。而不是指向一个点,可以在3到4之间画一条线
后面的代码
private void Button_Click(object sender, RoutedEventArgs e)
{
LineSeries ls = new LineSeries();
string inputX = this.t1.Text.ToString();
int inputY = Convert.ToInt32(this.t2.Text.ToString());
ChartValues.Add(new KeyValuePair<string, int>(inputX, inputY));
ls.Title = "temperature";
ls.IndependentValueBinding = new Binding("Key");
ls.DependentValueBinding = new Binding("Value");
ls.ItemsSource = ChartValues;
mchart.Series.Add(ls);
}
xaml代码
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:lineaxes"
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:DVC="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" x:Class="lineaxes.MainWindow"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<DVC:Chart Canvas.Top="80" Canvas.Left="10" Name="mchart" Width="400" Height="250" Loaded ="McChart_Loaded" Margin="339,107,53,62">
<DVC:Chart.Axes>
<DVC:LinearAxis Orientation="X" Title="Zeit"/>
<DVC:LinearAxis Orientation="Y" Location="Left" Title="temp1 "/>
<DVC:LinearAxis Orientation="Y" Location="Right" Title="temp2"/>
</DVC:Chart.Axes>
</DVC:Chart>
<TextBox x:Name="t1" HorizontalAlignment="Left" Height="23" Margin="152,107,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<Label Content="temp1" HorizontalAlignment="Left" Margin="38,107,0,0" VerticalAlignment="Top"/>
<Label Content="temp2" HorizontalAlignment="Left" Margin="54,178,0,0" VerticalAlignment="Top"/>
<TextBox x:Name="t2" HorizontalAlignment="Left" Height="23" Margin="184,178,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="113,271,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
</Grid>
enter image description here 输出图像已附加