How to plot dictionary values of each key in C#

Viewed 178

I want to plot a line graph a dictionary with multiple values of each key for series that have the same X value. I have checked other post, however they are mostly about python and the ones about c# have a dictionary structure different than mine. My dictionary looks like this:

[12/3/2020 10:34:47 AM (20, 21, 30, 50, 20)]
[12/3/2020 10:34:59 AM (22, 20, 20, 30, 12)]
[12/3/2020 10:35:10 AM (32, 39, 21, 23, 40)]

And my dictionary type:

Dictionary<DateTime, dynamic> data = new Dictionary<DateTime, dynamic>();

Value tuples are of type double where key types are DateTime. Here is what I have tried so far;

  chart1.Series.Add("series1");
  chart1.Series["series1"].Color = Color.Green;
  chart1.Series["series1"].Points.AddXY(data.Keys,data.Values);

The code above works for Keys but Values gives error saying values are not iterable.

I also tried a different way as below;

   chart1.DataSource = data; //data is the dictionary
   chart1.Series["series1"].XValueMember = "Key";
   chart1.Series["series1"].YValueMembers = "Value";

Again Values can not be displayed.

I can not access each tuple value to plot, (I could have created an array for tuple part but I want to learn how to do it with <dynamic>) can someone help me please?

0 Answers
Related