Charts databound to Datatable

3 posts, 0 answers
  1. Paul
    Paul avatar
    113 posts
    Member since:
    May 2009

    Posted 28 Aug 2009 Link to this post

    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. Robert
    Robert avatar
    82 posts
    Member since:
    Jun 2009

    Posted 28 Aug 2009 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 02 Sep 2009 Link to this post

    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.
Back to Top