[英]Add two lists as x and y coordinates in WPF Toolkit graph
I have two lists: 我有两个清单:
Temperature = new List<string>(reader.GetTemperature());
Time = new List<string>(reader.GetTime());
The Time list is the x-coordinates and the Temperature list is the y-coordinates. 时间列表是x坐标,温度列表是y坐标。
I have tried the following without any luck: 我已经尝试了以下方法,但没有任何运气:
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;
}
With the following XAML: 使用以下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>
Can anybody help? 有人可以帮忙吗?
Try the below code. 试试下面的代码。 I Hope you are trying to do. 我希望你正在努力。
<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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.