我想在 WPF 中创建一个 LineSeries 图表,我想将图表与数据库“温度”和“天”中的两个值绑定我认为下面的代码是准确的,但如果有任何人可以帮助我,我将不胜感激太多了 ..
private void combobox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string Value = combobox2.SelectedItem.ToString();
SQLiteConnection cnn = new SQLiteConnection("Data Source = MyDB.sqlite");
cnn.Open();
SQLiteCommand cmd = new SQLiteCommand("select * from weather1 where Town=@value ", cnn);
cmd.Parameters.AddWithValue("@value", Value);
List<string> temp = new List<string>();
List<string> day = new List<string>();
KeyValuePair<object, object> oops = new KeyValuePair<object, object>();
SQLiteDataReader sr = cmd.ExecuteReader();
while (sr.Read())
{
temp.Add(sr["temperature"].ToString());
day.Add(sr["day"].ToString());
}
oops = new KeyValuePair<object, object>(temp, day);
((LineSeries)Chart2.Series[0]).ItemsSource = oops.ToString();
cnn.Close();
}