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

How to bind datarow to a pie chart

9 Answers 1186 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Hanumesh
Top achievements
Rank 1
Hanumesh asked on 30 Apr 2007, 10:57 AM
HI,

I am trying to bind data to a pie chart from codebehind file. I am executing a stored procedure using data adapter which inturn returns a single row with 5 columns. I want to show this data on a pie chart along with these column names as legends.
please suggest me some solution.

Thanks in advance,
Hans.

9 Answers, 1 is accepted

Sort by
0
ernie racer
Top achievements
Rank 1
answered on 01 May 2007, 03:02 AM
i would like to help you, with some more information. where exactly do you have problems? did you notice that report chart control? do you already have a report?

daniel

ps: if you only need that pie (without other reports, printing or export), you can also use GDI+ and paint it by yourself (if you know how)
0
Hanumesh
Top achievements
Rank 1
answered on 02 May 2007, 05:58 AM
Thanks for the reply,

I want to add some more details to my query.
I am having a telerik report in my asp.net web application, and am inserting a telerik reporting chart of type pie. I could able to bind a datarow to this pie chart, but since the datasource is having a single row with 5 columns, I am getting multiple pie charts for each column. Actually it should display a single pie chart with these 5 column values. Its not happening, so what could be the reason, please give me some suggestions.
My requirement is to display a single pie chart which shows these 5 column values and also with legend values.

Thanks,
0
Chavdar
Telerik team
answered on 02 May 2007, 11:30 AM
Hi Hanumesh,

You cannot databind series items to columns. Therefore you should either change the query so that the data is returned in rows or manually transform the result into a suitable form. Here is an example:

private void chart1_NeedDataSource(object sender, System.EventArgs e) 
        { 
            Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart)sender; 
            
            SqlDataAdapter adapter1 = new SqlDataAdapter( 
                    @"SELECT TOP 1 * FROM Sales.vSalesPersonSalesByFiscalYears" 
                  , ConfigurationManager.ConnectionStrings["TelerikSampleDB"].ConnectionString); 
            adapter1.Fill(ds); 
 
            DataTable table = new DataTable(); 
            table.Columns.Add("Year"); 
            table.Columns.Add("Qty"); 
 
            table.Rows.Add(ds.Tables[0].Columns["2002"].ColumnName, ds.Tables[0].Rows[0]["2002"]); 
            table.Rows.Add(ds.Tables[0].Columns["2003"].ColumnName, ds.Tables[0].Rows[0]["2003"]); 
            table.Rows.Add(ds.Tables[0].Columns["2004"].ColumnName, ds.Tables[0].Rows[0]["2004"]); 
 
            chart.DataSource = table.DefaultView;             
        } 

You can verify this code with the Chart report example. Just replace the original chart1_NeedDataSource method with the new one. You should also change the type of the series to Pie and set DataLabelsColumn of the series to "Year".

Hope this helps.

Greetings,
Chavdar
the telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Hanumesh
Top achievements
Rank 1
answered on 03 May 2007, 05:39 AM
Thanks, the sample code gave me the exact solution.

But am not able to get the legends as required. Is it possible to customize the legends of pie chart?

I am facing one more problem, how can I display sum of a single column values in header/footer?


Thanks,
Hanumesh.
0
Chavdar
Telerik team
answered on 03 May 2007, 10:45 AM
Hi Hanumesh,

In order to populate the legend with the items' labels (instead of the series name) you should change the value of the [series].Appearance.LegendDisplayMode property to ChartSeriesLegendDisplayMode.ItemLabels. Custom legend items can be added to the chart only at design time.

In the Page Header/Footer sections you can use only PageNumber and PageCount as calculated fields. All the other expressions should be used from report items either in the Group Header/Footer or in the Detail sections.

Greetings,
Chavdar
the telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Paulo
Top achievements
Rank 2
answered on 26 Mar 2009, 12:43 PM
I had the same problem. For the multiple pie charts you sollution worked very well. transformed the table from a single row with 2 values into a table with 2 rows, 1 label text and 1 value per row.

Something like this:
Sex                   Avg Students Per Class
Male                           5,3
Female                       9,2

Now I do get a single pie char (with 1 single serie). Problem is I get 1 single legend with the series name "Avg Students Per Class".

I tried the sugestion in your second post but it didn't work, here is my code for the need datasource method:
Telerik.Reporting.Processing.Chart chart = sender as Telerik.Reporting.Processing.Chart; 
            chart.DataSource = GetSexAvgStudentsDS(); 
            chartSexo.Series[0].Type = Telerik.Reporting.Charting.ChartSeriesType.Pie; 
            chartSexo.Series[0].DataLabelsColumn = "Sex"

I get a runntime exception cause there are yet no series when the last 2 lines execute. I tried moving those to lines to an event handler for the OnDataBoundItem event, but the the series exist, but the last line haves no effect on the labels since databound already started.

Also tried to have the serie named "Avg Students Per Class" manually created in advanced, so I could apply the settings to datalabelscolumn before setting the datasource, but then the databind fails completly.

I'm out of ideas, would appreciate any help.

BTW, Can I have the table from the datasource displayed, with the correct labels under the graph using the Visual Properties visible option?
0
Hrisi
Telerik team
answered on 30 Mar 2009, 04:46 PM
Hi Paulo,

The reason for the exception is missing series definition. You can define series in design time or create one in the NeddDataSource event handler as shown below:

            Telerik.Reporting.Processing.Chart chart = sender as Telerik.Reporting.Processing.Chart;    
            Telerik.Reporting.Chart chartDefinition = chart.ItemDefinition as Telerik.Reporting.Chart;  
            chart.DataSource = GetSexAvgStudentsDS();    
            Telerik.Reporting.Charting.ChartSeries chartSeries1 = new Telerik.Reporting.Charting.ChartSeries();   
            chartSeries1.DataYColumn = "AvgStudentsPerClass";   
            chartSeries1.DataLabelsColumn = "Sex";   
            chartSeries1.Name = "Avg Students Per Class";   
            chartSeries1.Type = Telerik.Reporting.Charting.ChartSeriesType.Pie;   
            chartSeries1.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;   
            //chartDefinition.PlotArea.DataTable.Visible = true;  
            chartDefinition.Series.Clear();   
            chartDefinition.Series.AddRange(new Telerik.Reporting.Charting.ChartSeries[] {   
            chartSeries1});   


Kind regards,
Hrisi
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Jose Granja
Top achievements
Rank 1
answered on 18 Aug 2010, 05:24 PM
Hello,

could you tell me where I can find some examples of Reporting? I'm messing arround with the Chart Data and I would like to know how it's done. We bought the Telerik Reporting Package and I didn't come with examples. Is there anywhere where I could download them?

thank you
0
Steve
Telerik team
answered on 19 Aug 2010, 07:12 AM
Hello Jose,

The Telerik Reporting installation comes with examples. Their default location is C:\Program Files\Telerik\Reporting Q2 2010\Examples\CSharp\ReportLibrary for a 32 bit machine. If there is no such folder on your end, it is possible that you have deselected them upon install. If this is the case, please reinstall Telerik Reporting and select the examples. Another possible reason for their absence might be if your machine does not cover the system requirements, namely creating the AdventureWorks database used by the Reporting Examples requires SQLExpress/SQL Server 2005 or above to be installed on local machine. If you do not have SQLExpress/SQL Server 2005 or above on your machine, then the examples are automatically deselected in the installer. In this case you should install SqlExpress or later version of Sql Server on your machine and re-install Telerik Reporting.

All the best,
Steve
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Hanumesh
Top achievements
Rank 1
Answers by
ernie racer
Top achievements
Rank 1
Hanumesh
Top achievements
Rank 1
Chavdar
Telerik team
Paulo
Top achievements
Rank 2
Hrisi
Telerik team
Jose Granja
Top achievements
Rank 1
Steve
Telerik team
Share this question
or