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

Reporting Chart

1 Answer 47 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Carlos Nunez
Top achievements
Rank 1
Carlos Nunez asked on 15 Feb 2011, 04:48 PM
I have a database in the following form:

Date                    Green           Red          Yellow
02/15/2011         234               5248         0 
02/16/2011         24                 53             0 
02/17/2011         54                 248           0 
02/18/2011         72                 345           0 
02/19/2011         87                 36             0 

I wanted to make a PIE chart inside a Report in which  each 'slice'  represents the specified color (on the column name) and the data inside provides the size of the slice. So far I have not managed to find a way. Can you help?

Thanks in advance


1 Answer, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 17 Feb 2011, 05:04 PM
Hi Carlos,

I am afraid the chart would not support this case out of the box. The chart creates a ChartSeries for every column/property (that is pie in this case) and a ChartSeriesItem for every row (slice, that is). So by default, the chart  would go for three pies, each with 5 values for the corresponding dates.

Still, you can fill the chart manually by looping through the data and adding the chart items, here is an example:

DataTable tbl = GetData();
  
ChartSeries ser = new ChartSeries();
ser.Type = ChartSeriesType.Pie;
ser.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
foreach (DataRow row in tbl.Rows)
{
    ChartSeriesItem item = new ChartSeriesItem();
    double value = (double)row["Green"];
    item.YValue = value;
    item.Appearance.FillStyle.MainColor = Color.Green;
    item.Name = row["Date"].ToString() + " - " + value.ToString();
    item.Appearance.FillStyle.FillType = FillType.Solid;
    ser.Items.Add(item);
  
    item = new ChartSeriesItem();
// configure the item for Red color and add it to ser as the above one
  
// then create third item for Yellow
}
 
myChart.Series.Add(ser);

The above example sets the ChartSeriesItem.Name property, which will be shown in the legend as "date - value". You might want to configure it in a different manner, feel free to update/expand it.

Best regards,
Ves
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
Tags
General Discussions
Asked by
Carlos Nunez
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or