Is there a way to add Tool Tip Text to the legend items that get generated? I have Tool Tip Text on the Series object, but I would like it on the Legend Items as well.
Also, one other question, is there a way to customize how the legend shows the value next to the key? Right now, our legand keys are "ABC 123". I would like to add a "-" between the KEY and the COUNT value.
TIA
1 Answer, 1 is accepted
Hello, Mark,
Yes, you can add a tooltip to the legend items. You can use the ToolTipTextNeeded event and show the desired text when hovering legend items:
private void RadChartView1_ToolTipTextNeeded(object sender, ToolTipTextNeededEventArgs e)
{
LegendItemTitle legendItem = sender as LegendItemTitle;
if (legendItem != null)
{
e.ToolTipText = legendItem.Text;
}
}
According to your second question, if I understand you correctly you would like to customize the legend item title text. Please refer to the following code snippet:
this.radChartView1.ChartElement.LegendElement.Items[0].Title = "ABC-123";
More information about legend in RadChartView is available here: Legend - ChartView - Telerik UI for WinForms
I hope this helps. Should you have any other questions do not hesitate to contact me.
Regards,
Nadya | Tech Support Engineer
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
So, after digging around a little bit more and reading more in the help/docs link you provided, I am using the VisualItemCreating event to set the label and tooltip text as needed. However, I am getting TEXT overlap and I am not sure why.
Here is my code
private void HandleLegendElementVisualItemCreating(object sender, LegendItemElementCreatingEventArgs e)
{
e.ItemElement = new NtsLegendItemElement(e.LegendItem);
}
Here is my class, similar to the class in the example.
namespace Nts.Suite
{
public class NtsLegendItemElement : LegendItemElement
{
#region Public Constructors
public NtsLegendItemElement(LegendItem item) : base(item)
{
if (item.Element is DataPointElement dataPointElement)
{
if (dataPointElement.DataPoint.DataItem is ChartResults myResults)
{
ToolTipText = myResults.ToolTipText;
Text = $"{myResults.Category} ({myResults.Value:N0})";
}
}
}
#endregion Public Constructors
#region Protected Methods
protected override void Synchronize()
{
base.Synchronize();
SyncVisualStyleProperties(LegendItem.Element, TitleElement);
}
#endregion Protected Methods
}
}
This is my results
Okay, I think I have it figured out. Took a little trial and error, but I got it.
this is my updated CustomLegendItemElement class. This works perfectly
public class NtsLegendItemElement : LegendItemElement
{
#region Public Constructors
public NtsLegendItemElement(LegendItem item) : base(item)
{
if (item.Element is DataPointElement dataPointElement)
{
if (dataPointElement.DataPoint.DataItem is ChartResults myResults)
{
TitleElement.ToolTipText = myResults.ToolTipText;
item.Title = $"{myResults.Category} ({myResults.Value:N0})";
}
}
}
Here are my results (shown with ToolTipText) :)
Hello, Mark,
It seems that you managed to solve the problem you had with text overlapping. I am glad that your tooltips and custom NtsLegendItemElement are working fine. In case you have any other difficulties do not hesitate to contact us.