Use RadGridView as a datasource for RadChartView

2 posts, 1 answers
  1. Alden
    Alden avatar
    3 posts
    Member since:
    Nov 2015

    Posted 23 Nov 2015 Link to this post

    I constructed a RadGridView and would like to use its content for my RadChartView to create a pie chart, but so far nothing shows up.

    For RadGridView I would have five columns.

    Name     Count     C     D     E

     Germany  20

    France      50

    I would only use the "Name" and Count" column to construct my pie chart but not "C", "D", and "E" columns, so it would be a percentage chart with Germany 20/70 and France 50/70. How do I use these two columns of the RadGridView for my RadChartView?

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 23 Nov 2015 Link to this post

    Hello Alden,

    Thank you for writing.

    You can bind the controls to the same table, you only need to specify the ValueMember of the series:
    DataTable table;
     
    public RadForm1()
    {
        InitializeComponent();
        table = new DataTable();
        table.Columns.Add("Value", typeof(double));
        table.Columns.Add("Name", typeof(string));
        table.Rows.Add(1, "John");
        table.Rows.Add(3, "Adam");
        table.Rows.Add(5, "Peter");
        table.Rows.Add(12, "Sam");
        table.Rows.Add(6, "Paul");
     
        radGridView1.DataSource = table;
        radChartView1.AreaType = ChartAreaType.Pie;
        PieSeries lineSeria = new PieSeries();
        radChartView1.Series.Add(lineSeria);
        lineSeria.ShowLabels = true;
        lineSeria.DataSource = table;
       
        lineSeria.ValueMember = "Value";
        lineSeria.LegendTitleMember = "Name";
        radChartView1.ShowLegend = true;
    }

    Please let me know if there is something else I can help you with. 

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top