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

Pie Chart - Legend Value Problem

9 Answers 288 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Ajay Khedekar
Top achievements
Rank 1
Ajay Khedekar asked on 30 Jun 2009, 06:06 AM

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

Sort by
0
Velin
Telerik team
answered on 01 Jul 2009, 01:29 PM
Hello Ajay ,

There are three steps you need to do:
  1. To make RadChart showing the values in percents you need to this code:
    series.DefaultLabelValue = "#%"
  2. To make the chart legend showing a different label for each of the slices you need this code:
    series.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels; 
  3. 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.
0
Ajay Khedekar
Top achievements
Rank 1
answered on 01 Jul 2009, 01:55 PM

Thank you very much.............

this is exactly , what I needed..............

Thanks once again..........
0
Arjun
Top achievements
Rank 1
answered on 08 Nov 2010, 12:23 PM
Hi Telerik,

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
0
Ves
Telerik team
answered on 10 Nov 2010, 12:33 PM
Hello Arjun,

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
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
0
Arjun
Top achievements
Rank 1
answered on 11 Nov 2010, 01:44 PM

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?

 

0
Ves
Telerik team
answered on 16 Nov 2010, 01:54 PM
Hi Arjun,

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
Browse the vast support resources we have to jumpstart 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.
0
Arjun
Top achievements
Rank 1
answered on 23 Nov 2010, 04:53 PM
Thanks Admin.....
it spotlit me .

Thanks Agian
0
Nman
Top achievements
Rank 1
answered on 19 Apr 2011, 05:53 AM
Hello,

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.

0
Steve
Telerik team
answered on 21 Apr 2011, 10:02 AM
Hi Nman,

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.

Tags
Chart (Obsolete)
Asked by
Ajay Khedekar
Top achievements
Rank 1
Answers by
Velin
Telerik team
Ajay Khedekar
Top achievements
Rank 1
Arjun
Top achievements
Rank 1
Ves
Telerik team
Nman
Top achievements
Rank 1
Steve
Telerik team
Share this question
or