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

ToolTip on LegendLabel Silverlight RadChart

3 Answers 118 Views
Chart
This is a migrated thread and some comments may be shown as answers.
siva
Top achievements
Rank 1
siva asked on 04 Apr 2011, 03:26 PM

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

3 Answers, 1 is accepted

Sort by
0
Missing User
answered on 07 Apr 2011, 12:04 PM
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
0
Jonam
Top achievements
Rank 1
answered on 15 Jun 2012, 11:08 AM
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
0
Petar Marchev
Telerik team
answered on 19 Jun 2012, 07:27 AM
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 >>

Tags
Chart
Asked by
siva
Top achievements
Rank 1
Answers by
Missing User
Jonam
Top achievements
Rank 1
Petar Marchev
Telerik team
Share this question
or