ToolTip on LegendLabel Silverlight RadChart

4 posts, 0 answers
  1. siva
    siva avatar
    12 posts
    Member since:
    Nov 2010

    Posted 04 Apr 2011 Link to this post


    My Silverlight Rad Chart Legend label content is too length, I want to display a custom legend label and ToolTip to show the entire legend name.Is it possible. How i can do that thanks in advance. It is very urgent

    Thanks & Regards
    Siva
  2. Missing user
    Missing user avatar

    Posted 07 Apr 2011 Link to this post

    Hello siva,

    You can set a custom label via the SeriesMapping as following:
    SeriesMapping.LegendLabel = "Label Text";

    or you can manually generate legend items:
    radChart.DefaultView.ChartLegend.UseAutoGeneratedItems = false;
    ChartLegendItem item1 = new ChartLegendItem();
    item1.Label = "Item 1";
    radChart.DefaultView.ChartLegend.Items.Add( item1 );

    More information can be found in this help topic.

    Basically, to display a tooltip over a legend item is not supported in the control out of the box. However, you can try the following approach:
    private void radChart_DataBound(object sender, ChartDataBoundEventArgs e)
    {
        var dataSeries = radChart.DefaultView.ChartArea.DataSeries;
        for (int i = 0; i < dataSeries.Count; i++)
        {
            string toolTip = "custom text";
     
            ChartLegendItem legendItem = (radChart.DefaultView.ChartLegend as ItemsControl).Items[i] as ChartLegendItem;
            ToolTipService.SetToolTip(legendItem, toolTip);
        }
    }

    I hope this helps.


    Greetings,
    Polina
    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. DevCraft banner
  4. Jonam
    Jonam avatar
    19 posts
    Member since:
    Aug 2010

    Posted 15 Jun 2012 Link to this post

    Hello Polina,

    your approach for the tooltip works for me only if the legend is set to dataseries level. Is it possible to set the tooltip if the legend is set to item level?

    kind regards,

    Jonam
  5. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 19 Jun 2012 Link to this post

    Hi Jonam,

    You can update the code to have the items count in mind:
    private void radChart_DataBound(object sender, ChartDataBoundEventArgs e)
    {
     var dataSeries = radChart.DefaultView.ChartArea.DataSeries;
     int itemsCount = (radChart.DefaultView.ChartLegend as ItemsControl).Items.Count;
     for (int i = 0; i < itemsCount; i++)
     {
      string toolTip = "my tool tip text";
     
      ChartLegendItem legendItem = (radChart.DefaultView.ChartLegend as ItemsControl).Items[i] as ChartLegendItem;
      ToolTipService.SetToolTip(legendItem, toolTip);
     }
    }

    Another approach can be to retemplate the LegendItem:
    this.radChart.DefaultView.ChartArea.Legend.LegendItemStyle = this.Resources["ChartLegendItemStyle"] as Style;
    <Style x:Key="ChartLegendItemStyle" TargetType="telerik:ChartLegendItem">
     <Setter Property="Template">
      <Setter.Value>
       <ControlTemplate TargetType="telerik:ChartLegendItem">
        <TextBlock x:Name="PART_TextBlock"
          Grid.Column="1"
          Foreground="{TemplateBinding Foreground}"
          Margin="{TemplateBinding Margin}"
          Padding="{TemplateBinding Padding}"
          Text="{TemplateBinding Label}"
          ToolTipService.ToolTip="{Binding DataItem}" />
       </ControlTemplate>
      </Setter.Value>
     </Setter>
    </Style>

    Here the DataItem is the underlying business object and you have access to all of its properties. Here you can find the full LegendItem style.

    Kind regards,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top