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

Line Chart with Pivot Data?

6 Answers 99 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Vinny
Top achievements
Rank 1
Vinny asked on 13 May 2008, 10:13 PM
Hello,
I'm trying to create a line chart using pivot data returned from SQL Server. For example. Column 1 is a Product List and columns 2 - 13 represent each month of the year with a sales figure. Can anyone point me to a demo or sample that demonstrates how to get a line chart from this data.  I haven't gotten anywhere on my own and looking over the live demos application hasn't gotten me anywhere.

I'd like the y axis to be a 1 - 100,000 range and the x axis to represent the months of the year. Then a line representing each of the products. 

I appreciate the help.

Thank you,
Vinny

6 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 15 May 2008, 08:16 AM
Hello Vinny,

I am afraid RadChart does not support databinding to pivot data. Still, you can populate the chart manually by looping through the data like this:
for each row (product)
  Create a ChartSeries
  for each cell (field) in this row
    Create a ChartSeriesItem and add it to the above series
  end_inner_for
end_outer_for
 
I hope this helps.

Best wishes,
Ves
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Vinny
Top achievements
Rank 1
answered on 15 May 2008, 07:35 PM
Thank you Ves. would you by chance have a sample app to help me get started or perhaps point me to an appropriate example in the Live demos app?

Thanks,
Vinny
0
Accepted
Ves
Telerik team
answered on 16 May 2008, 12:16 PM
Hi Vinny,

Please, find attached a sample page with RadChart displaying pivot data, using the approach I mentioned. I hope it helps.

Best wishes,
Ves
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Vinny
Top achievements
Rank 1
answered on 16 May 2008, 01:45 PM
Thank you again Ves. This is very helpful in getting me started.
0
kollam2003
Top achievements
Rank 1
answered on 26 Jun 2008, 06:21 AM
will dis work with the2007 radchart??
0
Accepted
Giuseppe
Telerik team
answered on 26 Jun 2008, 06:48 AM
Hello kollam2003,

We are unsure which specific version of RadChart you are referring to but generally older versions of the control do not expose the BeforeLayout server-side event, so you should modify the code to handle the PrePaint event instead and you need to manually set the size for the axis item labels as well:

public partial class _Default : System.Web.UI.Page 
    DataTable tbl; 
    protected void Page_Load(object sender, EventArgs e) 
    { 
 
        tbl = new DataTable(); 
        DataColumn col = new DataColumn("ProductName"); 
        col.DataType = typeof(string); 
        tbl.Columns.Add(col); 
        col = new DataColumn("Jan"); 
        col.DataType = typeof(double); 
        tbl.Columns.Add(col); 
        col = new DataColumn("Feb"); 
        col.DataType = typeof(double); 
        tbl.Columns.Add(col); 
        col = new DataColumn("March"); 
        col.DataType = typeof(double); 
        tbl.Columns.Add(col); 
        tbl.Rows.Add(new object[] { "P1", 2, 19, 11 }); 
        tbl.Rows.Add(new object[] { "P2", 12, 13, 14 }); 
        tbl.Rows.Add(new object[] { "P3", 22, 5, 7 }); 
        tbl.Rows.Add(new object[] { "P4", 9, 6, 2 }); 
 
        foreach (DataRow row in tbl.Rows) 
        { 
            ChartSeries ser = new ChartSeries(row["ProductName"].ToString(), ChartSeriesType.Line); 
 
            for (int i = 1; i < tbl.Columns.Count; i++) 
            { 
                ChartSeriesItem item = new ChartSeriesItem((double)row[i]); 
                ser.Items.Add(item); 
            } 
            RadChart1.Series.Add(ser); 
        } 
 
        RadChart1.PlotArea.XAxis.Appearance.LabelAppearance.Dimensions.AutoSize = false
        RadChart1.PlotArea.XAxis.Appearance.LabelAppearance.Dimensions.Height = 20
        RadChart1.PlotArea.XAxis.Appearance.LabelAppearance.Dimensions.Width = 50
    } 
 
    protected void RadChart1_PrePaint(object sender, EventArgs e) 
    { 
        for (int i = 0; i < RadChart1.PlotArea.XAxis.Items.Count; i++) 
        { 
            RadChart1.PlotArea.XAxis.Items[i].TextBlock.Text = tbl.Columns[i + 1].ColumnName; 
        } 
    } 
 



Regards,
Manuel
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Chart (Obsolete)
Asked by
Vinny
Top achievements
Rank 1
Answers by
Ves
Telerik team
Vinny
Top achievements
Rank 1
kollam2003
Top achievements
Rank 1
Giuseppe
Telerik team
Share this question
or