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

How to databind a PIE chart?

1 Answer 230 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ramon serrano
Top achievements
Rank 1
ramon serrano asked on 01 Mar 2010, 03:35 PM
Hi! I have a problem, i would like to databind a PIE in a report, my code for binding a pie chart manually is like SAMPLE A, but i would like to assign YValue from a database, like the SAMPLE B, where i databind a bar chart from a database...

SAMPLE A
private void chart1_NeedDataSource(object sender, EventArgs e)  
        {  
            chart1.Width = Unit.Pixel(300);  
            chart1.Height = Unit.Pixel(300);  
            ChartSeries s = new ChartSeries();  
            s.Name = "NameOfSerie";  
            s.Type = ChartSeriesType.Pie;  
            for (int i = 1; i < 6; i++)  
            {  
                ChartSeriesItem item = new ChartSeriesItem();  
                item.YValue =i* 3.5;  
                item.Label.TextBlock.Text = "A" + i.ToString();  
                s.Items.Add(item);               
            }  
            s.Appearance.LegendDisplayMode =ChartSeriesLegendDisplayMode.Nothing;  
            chart1.Series.Add(s);  
        } 

SAMPLE B
private void chart1_NeedDataSource(object sender, EventArgs e)  
        {  
            string sql =  @"SELECT TOP 10 Production.Product.ListPrice, Production.Product.Name, Production.Product.ProductID FROM Production.Product";  
            string connectionString ="Data Source=localhost;Initial Catalog=AdventureWorks;Integrated Security=True";  
            SqlDataAdapter adapter = new SqlDataAdapter(sql, connectionString);  
            DataSet dataSet = new DataSet();  
            adapter.Fill(dataSet);  
            ChartSeries series = new ChartSeries();  
            series.DataYColumn = "ProductID";  
            series.DataLabelsColumn = "Name";  
            chart1.SeriesOrientation=ChartSeriesOrientation.Horizontal;  
            chart1.Width =Unit.Pixel(300);  
            chart1.Height = Unit.Pixel(300);  
            chart1.Series.Add(series);  
            (sender as Telerik.Reporting.Processing.Chart).DataSource = dataSet.Tables[0].DefaultView;   
        } 


I would like to fill a pie chart from a database, instead of a bucle...I mean...Something similar to SAMPLE B, where you can assign a DataYColumn, a field from the datasource...


Thanks for your time and i hope to find some help here...

1 Answer, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 03 Mar 2010, 10:03 AM
Hello Ramon,

We are not sure we understand your inquiry. Did you mean that you are unable to bind your Chart to a database? If that is the case please check out the following help resources.
 
Working with Charts in Telerik Reports
Data Binding Chart to a Database Object

Let us know if you need additional assistance.

Regards,
Peter
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
ramon serrano
Top achievements
Rank 1
Answers by
Peter
Telerik team
Share this question
or