在 WPF 工具包图形中添加两个列表作为 x 和 y 坐标
Add two lists as x and y coordinates in WPF Toolkit graph
我有两个列表:
Temperature = new List<string>(reader.GetTemperature());
Time = new List<string>(reader.GetTime());
时间列表是 x 坐标,温度列表是 y 坐标。
我尝试了以下方法,但没有成功:
private void LoadDataChart()
{
List<KeyValuePair<string, string>> data = new List<KeyValuePair<string, string>>();
foreach (string s in Temperature)
{
data.Add(new KeyValuePair<string, string>(s, null));
}
foreach (string t in Time)
{
data.Add(new KeyValuePair<string, string>(null, t));
}
dataChart.DataContext = data;
}
与以下XAML:
<chartingToolkit:Chart x:Name="dataChart" HorizontalAlignment="Left" Margin="342,84,0,0" Title="" VerticalAlignment="Top" Height="300" Width="565" IsEnabled="False" LegendTitle="">
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="False" />
</chartingToolkit:Chart>
有人可以帮忙吗?
试试下面的代码。我希望你正在努力做。
<wpfTool:Chart x:Name="dataChart" HorizontalAlignment="Left" Margin="342,84,0,0" Title="" VerticalAlignment="Top" Height="300" Width="565" IsEnabled="False" LegendTitle="">
<wpfTool:LineSeries DependentValuePath="Value" IndependentValuePath="Key" x:Name="series" IsSelectionEnabled="False" />
</wpfTool:Chart>
public partial class Window3 : Window
{
public Window3()
{
InitializeComponent();
LoadColumnChartData();
}
List<string> Temperature = new List<string>() { "60", "65" };
List<string> Time = new List<string>() { "1/28/2015 12:00:00", "1/28/2015 2:20:35" };
private void LoadColumnChartData()
{
int countTemp = Temperature.Count;
int countTime = Time.Count;
List<KeyValuePair<DateTime, double>> data1 = new List<KeyValuePair<DateTime, double>>();
if(countTemp==countTime)
{
for (int i = 0; i < countTemp; i++)
{
KeyValuePair<DateTime, double> dt = new KeyValuePair<DateTime, double>(DateTime.Parse(Time[i]),Convert.ToDouble(Temperature[i]));
data1.Add(dt);
}
}
series.ItemsSource = data1;
}
}
我有两个列表:
Temperature = new List<string>(reader.GetTemperature());
Time = new List<string>(reader.GetTime());
时间列表是 x 坐标,温度列表是 y 坐标。
我尝试了以下方法,但没有成功:
private void LoadDataChart()
{
List<KeyValuePair<string, string>> data = new List<KeyValuePair<string, string>>();
foreach (string s in Temperature)
{
data.Add(new KeyValuePair<string, string>(s, null));
}
foreach (string t in Time)
{
data.Add(new KeyValuePair<string, string>(null, t));
}
dataChart.DataContext = data;
}
与以下XAML:
<chartingToolkit:Chart x:Name="dataChart" HorizontalAlignment="Left" Margin="342,84,0,0" Title="" VerticalAlignment="Top" Height="300" Width="565" IsEnabled="False" LegendTitle="">
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding}" IsSelectionEnabled="False" />
</chartingToolkit:Chart>
有人可以帮忙吗?
试试下面的代码。我希望你正在努力做。
<wpfTool:Chart x:Name="dataChart" HorizontalAlignment="Left" Margin="342,84,0,0" Title="" VerticalAlignment="Top" Height="300" Width="565" IsEnabled="False" LegendTitle="">
<wpfTool:LineSeries DependentValuePath="Value" IndependentValuePath="Key" x:Name="series" IsSelectionEnabled="False" />
</wpfTool:Chart>
public partial class Window3 : Window
{
public Window3()
{
InitializeComponent();
LoadColumnChartData();
}
List<string> Temperature = new List<string>() { "60", "65" };
List<string> Time = new List<string>() { "1/28/2015 12:00:00", "1/28/2015 2:20:35" };
private void LoadColumnChartData()
{
int countTemp = Temperature.Count;
int countTime = Time.Count;
List<KeyValuePair<DateTime, double>> data1 = new List<KeyValuePair<DateTime, double>>();
if(countTemp==countTime)
{
for (int i = 0; i < countTemp; i++)
{
KeyValuePair<DateTime, double> dt = new KeyValuePair<DateTime, double>(DateTime.Parse(Time[i]),Convert.ToDouble(Temperature[i]));
data1.Add(dt);
}
}
series.ItemsSource = data1;
}
}