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

data question

1 Answer 62 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
adi
Top achievements
Rank 1
adi asked on 27 Oct 2008, 12:12 PM
Hi,

I'm not familiar with RadChart. I fiddle with it. I have a simple question now. I'd like to bind a simple DataTable to a Chart programmatically. The DataTable columns collection holds the values that I like to display as X axis and the Rows collection holds the values for the Y axis. How can I tell the RadChart to use the columns as X? I can't found something like 'use pivot'.

1 Answer, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 29 Oct 2008, 08:16 AM
Hi adi,

Unfortunately, RadChart does not provide pivot functionality. Still, you can display such chart by adding the chart series and their items manually, here is an example:

DataTable tbl = new DataTable(); 
        DataColumn col = new DataColumn("Col1"); 
        col.DataType = typeof(double); 
        tbl.Columns.Add(col); 
        col = new DataColumn("Col2"); 
        col.DataType = typeof(double); 
        tbl.Columns.Add(col); 
 
        tbl.Rows.Add(new object[] { 2, 17 }); 
        tbl.Rows.Add(new object[] { 3, 19 }); 
        tbl.Rows.Add(new object[] { 4, 15 }); 
 
        RadChart1.PlotArea.XAxis.AutoScale = false
        foreach (DataColumn column in tbl.Columns) 
        { 
            RadChart1.PlotArea.XAxis.AddItem(column.ColumnName); 
        } 
        foreach (DataRow row in tbl.Rows) 
        { 
            ChartSeries ser = new ChartSeries(); 
            RadChart1.Series.Add(ser); 
            ser.Name = "Series " + ser.Index; 
            foreach (DataColumn column in tbl.Columns) 
            { 
                ser.Items.Add(new ChartSeriesItem((double)row[column])); 
            } 
        } 

Hope this helps.

Regards,
Ves
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Chart (Obsolete)
Asked by
adi
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or