This is a migrated thread and some comments may be shown as answers.

Charts databound to Datatable

2 Answers 119 Views
Chart (obsolete as of Q1 2013)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul
Top achievements
Rank 1
Paul asked on 28 Aug 2009, 09:36 PM
Hi,
    How can I do the following.

I have a radchart set to be a pie chart and I have a datatable with many columns in it. When I set the datasource of the chart to the datatable I get results for every column. What I want to do is get it to create a pie chart on just one column. How do I achieve this?

radChart1.DataSource = Myds; //Is the datatable with many columns


What do I set on radchart to just use one column from that table.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 28 Aug 2009, 11:16 PM
Hi Paul,

After binding the chart, you could try removing the unnecessary series that were picked up from the data source.

            radChart1.DataSource = Myds; 
            radChart1.DataBind(); 
 
            for (int i = radChart1.Series.Count - 1; i >= 0; i--) 
            { 
                ChartSeries series = radChart1.Series[i]; 
                if (series.Name != "ColumnName"
                    radChart1.Series.Remove(series); 
            } 

I hope this helps.

- Robert
0
Ves
Telerik team
answered on 02 Sep 2009, 08:31 AM
Hi guys,

Robert's suggestion will surely work, but let me mention, that RadChart can deal with situations like this. You can create your own series and add it to the Series collection of the chart. Then, when databinding the chart will not create a series for each column, but it will keep those you have created. There is a single requirement -- set the DataYColumn property. Here is an example:

ChartSeries ser = new ChartSeries("MySeries", ChartSeriesType.Pie); 
ser.DataYColumn = "MyDataColumn"
radChart1.Series.Add(ser); 

Alternatively, you can take advantage of RadChart's DataManager:

radChart1.DataManager.ValuesYColumns = new string[] { "MyDataColumn" }; 

In the end, the result will be the same - a single series populated by the data in "MyDataColumn".

Sincerely,
Ves
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Chart (obsolete as of Q1 2013)
Asked by
Paul
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Ves
Telerik team
Share this question
or