0

I have two dictionaries, from which want to show stacked-column chart. I tried but don't understand where I am going wrong:

chartname.DataSource = EventcategoryopenCount;
chartname.Series["OPEN"].XValueMember = "Key";
chartname.Series["OPEN"].YValueMembers = "Value";
chartname.DataSource = EventcategoryreductCount;
chartname.Series["Close"].XValueMember = "Key";
chartname.Series["Close"].YValueMembers = "Value";
chartname.DataBind();

If I only use one dictionary it creates output but when I am using both dictionaries nothing is showing in graph.

TaW
  • 53,122
  • 8
  • 69
  • 111
jack
  • 11
  • 4
  • Why are you repeating the first 3 lines? – richej Jun 13 '18 at 13:01
  • I had edited a code – jack Jun 13 '18 at 13:02
  • 1
    I think you need to post more code. What kind of Chart is it? Why are you doing `chartname.DataSource = EventcategoryreductCount` twice? – richej Jun 13 '18 at 13:05
  • We need to see or at least know more about the data. What types? What values? If you use more than one Series on a StackedColumn chartType they [MSDN](https://msdn.microsoft.com/en-us/library/dd489221.aspx) should be [aligned](https://msdn.microsoft.com/en-us/library/dd456707.aspx) - See [here for more](https://stackoverflow.com/questions/35744549/stacked-column-chart-in-c-sharp)! – TaW Jun 13 '18 at 13:12
  • 1
    I have only once used EventcategoryreductCount. I have two dictionary, in both dictionary key is same but value is different. and i want that key to plot in graph. like IF I would take one dictionary key "march" so for that in EventcategoryopenCount dic. key will be 13 and for EventcategoryreductCount dic. key will be 12. so i want to plot them in one stack-column graph is it possible? – jack Jun 13 '18 at 13:13
  • And the same number of values? Also: (And most importantly) You should __not bind to the chart but to the respective Series.Points__! Also: It is good practice to __first set the members and then the datasource__! – TaW Jun 13 '18 at 13:14
  • yes dictionary value will be same and with same in order but key value will be different – jack Jun 13 '18 at 13:21

1 Answers1

0

You must use a different way to do data binding if your two series shall have different datasources.

There are several.. (Here is another post about a similar topic.)

You should not bind to the chart but to the respective Series.Points!

Change the code to:

chartname.Series["OPEN"].Points.DataBind(EventcategoryopenCount, "Key", "Value", "");
chartname.Series["Close"].Points.DataBind(EventcategoryreductCount, "Key", "Value", "");

Btw: It is good practice to first set the members and then the datasource but this method will do it both in one call..

Your data still need to be aligned.

TaW
  • 53,122
  • 8
  • 69
  • 111