Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Add multiple series on bar chart using datatable (Read 3336 times)
abhi dhotre
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Joined: Jul 12th, 2017
Add multiple series on bar chart using datatable
Jul 12th, 2017 at 5:13pm
Print Post  
Hi All,
I have attached screenshot of the datatable I'm using. I need to have months on Y-Axis, and the columns as different series in barchart. Now, I'm facing following problems:
1) When I'm using one column the bar is displayed but the barchart.series.count() shows count of series as 0. The following is the code:
barChart1.DataSource = dt;
barChart1.XDataFields = new ObservableCollection<string> { "iPhoneSE" }
barChart1.XAxisLabelsDataFields = new ObservableCollection<string> { "TheMonth" }

2) How to add multiple series in a bar chart. I'm using following code but the series count remains to be 0 even if I can see on barchart.
barChart1.DataSource = dt;
barChart1.XDataFields = new ObservableCollection<string> { "iPhoneSE" }
barChart1.XAxisLabelsDataFields = new ObservableCollection<string> { "TheMonth" }
barChart1.YDataFields = new ObservableCollection<string> { "iPhoneSE", "iPhone7", "iPhone6S", "iPhone6" };
3) If I use areaChart then the count of series changes with the same code. But I wanr to display in barchart.
Regards,
Abhi D Smiley
  

Capture.PNG ( 48 KB | 189 Downloads )
Capture.PNG
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Add multiple series on bar chart using datatable
Reply #1 - Jul 12th, 2017 at 5:41pm
Print Post  
Hi,

I think these will show in Series.Count only after you call DataBind. Have you checked the count before or after when using BarChart?

If you want to show multiple series, you can add one column to XDataFields (e.g. Id) and the value columns to YDataFields. As we discussed on the Helpdesk, I will check with our developer if there's a way to show the series without specifying anything in XDataFields.

Also note that instead of setting DataSource and calling DataBind, you can create DataBoundSeries objects and add them to chart.Series, setting X/YDataField for each instance.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
abhi dhotre
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Joined: Jul 12th, 2017
Re: Add multiple series on bar chart using datatable
Reply #2 - Jul 12th, 2017 at 6:08pm
Print Post  
Hey thanks Slavcho, the databind worked. I can get the count of the series now. The only problem now remains with the XDataFields as I do not have any Id column in my datatable.

Regards,
Abhi
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Add multiple series on bar chart using datatable
Reply #3 - Jul 12th, 2017 at 6:41pm
Print Post  
Hi Abhi,

Please check if this build works for you -
https://mindfusion.eu/_temp/chart_bind_autoid.zip

It should let you leave XDataFields unassigned and pass the column names to YDataFields.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
abhi dhotre
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Joined: Jul 12th, 2017
Re: Add multiple series on bar chart using datatable
Reply #4 - Jul 12th, 2017 at 7:50pm
Print Post  
Hi Slavcho,
I figured out the problem by adding a dummy ID column in the datatable and it worked as wanted by me. I will check the new libraries and update you on that.
Thanks for your time.
Regards,
Abhi
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint