0

I want to create a LineSeries chart in WPF, i want to bind chart with two value from database "temperature" and "day" i think this below codes are accurate but doesn't work if there is any one could help me i will appreciate too much ..

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();
}
kennyzx
  • 12,845
  • 6
  • 39
  • 83
  • There are other errors, but an obvious one is that you are setting `ItemsSource` to a string - you should not call `oops.ToString()`, just bind it to `oops`. – kennyzx Oct 25 '15 at 12:47
  • And oops should be **a list** of `KeyValuePair`, not one single `KeyValuePair`. – kennyzx Oct 25 '15 at 12:50
  • @ kennyzx tnq for your help you know when i bind it just with oops , there is some error also . – belle.elly Oct 25 '15 at 12:52
  • This is [an example](http://stackoverflow.com/questions/16280122/dvc-line-series-chart-with-multiple-series), HTH. – kennyzx Oct 25 '15 at 12:54

0 Answers0