Radchart - Pie chart Legend not as expected

Thread is closed for posting
9 posts, 0 answers
  1. pradip
    pradip avatar
    40 posts
    Member since:
    Feb 2009

    Posted 15 Jul 2010 Link to this post


    I was trying to generate the Pie chart. Everything was fine except the Legend. It is giving me - Item1, Item2 Item3 etc instead of actual item values... 

    Have look at the code,

            Dim chaSer As New ChartSeries
            radChart.ChartTitle.TextBlock.Text = "Polling Result"
            radChart.Skin = "WebBlue"
            radChart.Attributes.Add("Palette", "Colorful")

                chaSer.Type = ChartSeriesType.Pie
                chaSer.DefaultLabelValue = "#%"
                chaSer.Appearance.ShowLabels = True
            chaSer.DataYColumn = "Count"

            chaSer.Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels

            radChart.DataSource = dtPoll

            Response.ContentType = "image/png"
            radChart.Save(Response.OutputStream, ImageFormat.Jpeg)

  2. Velin
    Velin avatar
    391 posts

    Posted 19 Jul 2010 Link to this post

    Hello pradip,

    There are a couple of steps you need to do:
    1. Register for the ItemDataBound event and set value to the Name property of each item. This value will be displayed in the legend. Here is the sample code:
      Copy Code
      <telerik:RadChart ID="RadChart1" runat="server" OnItemDataBound="ItemDataBound"> 
          public void ItemDataBound(object sender, ChartItemDataBoundEventArgs e) 
              e.SeriesItem.Name = dataSource.Rows[e.SeriesItem.Index]["LegendName column"].ToString(); 
    2. Set the series Appearance.LegendDisplayMode to ItemLabels. This instructs the legend to show labels for each item in the series.
      Copy Code
       <telerik:ChartSeries Appearance-LegendDisplayMode="ItemLabels" Type="Pie" DataYColumn="CurrentDrainPercentage" /> 

    Where the "LegendNameColumn" string should be replaced with the name of the column from your data source that holds the legend labels. 

    Best wishes,
    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
  3. Celeste
    Celeste avatar
    44 posts
    Member since:
    Oct 2010

    Posted 11 Nov 2010 Link to this post

    I am experiencing the same issue. The chart is using a SqlDataSource but the 
    SqlDataSource object has no .Rows property. Please identify the object type of your dataSource object or assist. Thank you.
  4. Velin
    Velin avatar
    391 posts

    Posted 17 Nov 2010 Link to this post

    Hi Celeste,

    You can find the respective row from the data source using code like this:
    public void ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
        e.SeriesItem.Name = (e.DataItem as DataRowView).Row["Name"].ToString();

    Where "Name" is actually column name used for legend labels.

    Kind regards,
    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.
  5. Celeste
    Celeste avatar
    44 posts
    Member since:
    Oct 2010

    Posted 17 Nov 2010 Link to this post

    Thank you, that helped!
  6. kamal
    kamal avatar
    1 posts
    Member since:
    May 2011

    Posted 24 May 2011 Link to this post

    i have a problem with pie chart legends

    this is the code i have implemented :

    PieSeriesDefinition lineDefinition = new PieSeriesDefinition();
    lineDefinition.SeriesName = strElementName;                    
    lineDefinition.LegendDisplayMode = LegendDisplayMode.SeriesLabel;

    i have data for 2 elements, chart shows data for 2 elements but the color of both the elements is same, also it shows only one legend, it should have shown  2 legends.
    i am using auto generated legends.
    if i generate legends, how to color those legends to get the default colors as i am not changing the default colors of the chart area.

  7. Marbry
    Marbry avatar
    26 posts
    Member since:
    Aug 2012

    Posted 31 Aug 2011 Link to this post

    The last example given retrieves the correct data, but it's not being displayed in the legend.

    The example you gave doesn't seem to be right, why would you populate the name, then set the display mode to label?

    Shouldn't there be a ChartSeriesLegendDisplayMode.ItemNames ?


  8. Ves
    Ves avatar
    2926 posts

    Posted 05 Sep 2011 Link to this post

    Hello Marbry,

    I agree, this is a bit misleading. The Name provides the value to display in the legend, while the Label provides the string for the label. In case you need them equal, you can populate them with the same values.

    Kind regards,
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  9. marinus bosman
    marinus bosman avatar
    4 posts
    Member since:
    Apr 2005

    Posted 06 Oct 2011 Link to this post

    [Deleted: Posted in Wriong Thread]
Back to Top