在wpf中将图表值与数据库绑定

时间:2015-10-25 11:29:04

标签: wpf data-binding lineseries

我想在WPF中创建一个LineSeries图表,我想用数据库中的两个值绑定图表"温度"和" day"我认为下面的代码是准确的,但如果有任何人可以帮助我,我会非常感激..

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

0 个答案:

没有答案