Hello,
I have create a Pie chart with following Dataset schema
CallPriorityCode CallPriorityName NoOfCalls
1 Low 8
2 Medium 10
3 High 2
I want to show Pie chart with Percentage value ( Of NoOfCalls Data) as Lable and Call Priority Name in Legend Area.
But I can Show either of them only, I can not set "CallPriorityName " to DataYColumn Property
as this property requires Integer Data .
MY Code :-
<
telerik:RadChart ID="radchartCallsByPriority" runat="server"
Skin="LightGreen" AutoLayout="true" Height="250px" Width="450px" PlotArea-EmptySeriesMessage-TextBlock-Text="No calls found" >
<Series>
<telerik:ChartSeries Name="No. Of Calls" Type="Pie" DefaultLabelValue="#%" DataYColumn="NoOfCalls" Appearance-LabelAppearance-LabelLocation="Inside" Appearance-LegendDisplayMode="ItemLabels" Appearance-LabelAppearance-Visible="true">
</telerik:ChartSeries>
</Series>
<PlotArea>
<XAxis Appearance-LabelAppearance-RotationAngle="-45" Appearance-TextAppearance-AutoTextWrap="False" AxisLabel-TextBlock-Appearance-TextProperties-Font="20px">
</XAxis>
</PlotArea>
<ChartTitle>
<TextBlock Text="Calls By Priority" Visible="false" />
</ChartTitle>
</telerik:RadChart>
Any Help would be Higly appreciated.
Thanks in Advance
----------------------------------------------------
Ajay
9 Answers, 1 is accepted
There are three steps you need to do:
- To make RadChart showing the values in percents you need to this code:
series.DefaultLabelValue = "#%"; - To make the chart legend showing a different label for each of the slices you need this code:
series.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels; - The chart legend uses the value stored in the Name property of the chart items to show the corresponding legend item. You should subscribe to the ItemDataBound event of the control and manually set the Name property of each item. Here is the code:
RadChart1.ItemDataBound += new EventHandler<ChartItemDataBoundEventArgs>(RadChart1_ItemDataBound); void RadChart1_ItemDataBound(object sender, ChartItemDataBoundEventArgs e) { e.SeriesItem.Name = (e.DataItem as DataRowView).Row[0].ToString(); }
Please find attached a simple project demonstrating the above steps.
Hope this helps.
All the best,
Velin
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thank you very much.............
this is exactly , what I needed..............
Thanks once again..........
can i do same for Telerik.Reporting.Chart -chart1 (which is not a telerik:RadChart control).
Like :
private
void chart1_ItemDataBound(object sender, EventArgs e)
{
//e.SeriesItem.Name = (e.DataItem as DataRowView).Row[0].ToString();
}
Please help me ASAP.
thanks in advance
--------------------------
Dhungana
ItemDataBound cannot be used in Telerik Reporting chart item in the same way it is used in RadChart for ASP.NET AJAX. Can you please describe your scenario in details, so we can advise you further?
Kind regards,
Ves
the Telerik team
Thanks for prompt response.
finally i developed a logic as below .
private void chart1_NeedDataSource(object sender, EventArgs e)
{
DataSet chartdSet = GetDataSet();
if (chartdSet.Tables[0].Rows.Count > 0)
{
Telerik.Reporting.Processing.Chart _chart = ((Telerik.Reporting.Processing.Chart)sender);
PopulateChartSeriesItems(chartdSet, _chart);
}
}
private void PopulateChartSeriesItems(DataSet _dSet,Telerik.Reporting.Processing.Chart _chart)
{
foreach (DataRow dr in _dSet.Tables[0].Rows)
{
ChartSeriesItem item = new ChartSeriesItem();
item.Name = dr["field1"].ToString() + "(" + dr["field2"].ToString()+")"; //field2 is count (numeric type)
item.YValue = (double)int.Parse(dr["field2"].ToString());
item.Label.TextBlock.Text = dr["field2"].ToString();
chart1.Series[0].Items.Add(item);
//check if table has data greater then default threshold
if (chart1.Series[0].Items.Count > 4)
{
_chart.Height = _chart.Height + Unit.Inch(0.3); //increase height of chart to make good looks for large no of data and to fit all items label in legend area
}
}
//check if table has data less then default threshold ---Default threshold is 4
if (_dSet.Tables[0].Rows.Count < 4)
{
_chart.Height = _chart.Height - Unit.Inch(0.25 * _dSet.Tables[0].Rows.Count); //decrease height of chart to make good looks for small no of data
}
}
it works me up to certain extend,i mean its working fine but there is UI issue for huge data (like more than 30).
please give a glance over attached snapshot for UI issues.
Finally , is there any way to automatically fit the height of legend according to runtime data?
The reason for not displaying all the labels might be in the fact that IntelligentLabelsEnabled property is set to true, is that the case? While this feature helps in certain cases, when the chart is heavily loaded, the labels become too many, so it is harder to find non-overlapping positions. This leads to two effects, first there is a performance penalty imposed by the continuous search for positions and then, some labels are hidden. I believe the "-" label is related to this too. It might be a glitch caused by positioning and hiding these labels. I would suggest setting IntelligentLabelsEnabled property to false and in addition you can increase the distance from the pie to the labels by setting the ChartSeries.Appearance.LabelAppearance.Distance property with a value like 20 or 30 (you can adjust this according to your specific needs).
Finally, the legend is as high as its items need it to be. Unfortunately, the chart size cannot be adjusted according to its content, so it seems the chart is a bit higher than you need. I can see you have already found how to increase its size, depending on the number of items added. It seems that the empty space in the bottom is caused by these manual settings, you can try decreasing the value added to the chart height for each item by a tiny bit, to see if this fixes it.
Kind regards,
Ves
the Telerik team
it spotlit me .
Thanks Agian
My problem is same like mentioned originally but i am using Telerik reporting and not RadControls, i couldnot solve it till now, kindly respond ASAP.
I have create a Pie chart with following Dataset schema
CallPriorityCode CallPriorityName NoOfCalls
1 Low 8
2 Medium 10
3 High 2
I want to show Pie chart with Percentage value ( Of NoOfCalls Data) as Lable and Call Priority Name in Legend Area.
You would have to create the chart series and items programmatically in the NeedDataSource event in order to be able to achieve your inquiry. A sample code that gets this done is available in the Data Binding Chart to a Generic List of Objects help article. Review it carefully and let us know how it goes.
Best wishes,
Steve
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.