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

Pie labels with % from databound data

1 Answer 32 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Jon asked on 27 Sep 2009, 12:10 PM
I'm getting my data for the chart from a linq query

            var reportData = from a in data  
                             group a by a.OrderType  
                                 into b  
                                 select new   
                                     OrderType = b.Key,  
                                     Orders = b.Count(),  
                                     OrderTotal = b.Sum(p => p.OrderTotal),  
                                     Tax = b.Sum(p => p.Tax),  
                                     Costs = b.Sum(p => p.ActualCost),  
                                     Profit = b.Sum(p => p.Profit)  

And setting the data in NeedDataSource

            var procChart = (Telerik.Reporting.Processing.Chart)sender;  
            var defChart = (Telerik.Reporting.Chart)procChart.ItemDefinition;  
            var series = new ChartSeries  
                                 Type = ChartSeriesType.Pie,   
                                 DataYColumn = chartColumn,   
                                 DataLabelsColumn = "OrderType",   
                                 DefaultLabelValue = "#Y - #%" 
            procChart.DataSource = DataSource; 

where chartColumn is OrderTotal, Profit, Costs, or Orders depending on the chart.  The DefaultLabelValue I understand is getting ignored because of the DataLabelsColumn.  Is there a way to supply the "#Y - #%" to the chart along with the DataLabelsColumn as it would be needed for the label as well?

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 28 Sep 2009, 07:24 AM
Hello Jon,

Indeed DefaultLabelValue and DataLabelsColumn properties "self-exclude" each other (we've reported this to our charting team already), so the workaround we suggest is to manually create the series and populate the series items. The item.Name property is shown in the Legend and the item.Label.TextBlock.Text is shown as the label for the corresponding pie e.g.:

 foreach (DataRow row in table.Rows)
                ChartSeriesItem item = new ChartSeriesItem();
                item.YValue = (double)row["Value"];
                item.Name = (string)row["Name"];                
                item.Label.TextBlock.Text = (string)row["Name"] + " - #%";

Kind regards,
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
General Discussions
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question