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

Trackball Label Text Coloring

1 Answer 168 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 30 Mar 2017, 05:44 PM

I have changed the Label on the Trackball to the data I want to display. In this case it is 4 lines. I would like to change the color of each line of text individually. I can change the color of all of the text in the label, but not on a line by line basis. Here is a snippet of my code:

ChartTrackballController trackBallController = new ChartTrackballController();
trackBallController.TextNeeded += TrackBallController_TextNeeded;
radChartView1.Controllers.Add(trackBallController);

 

private void TrackBallController_TextNeeded(object sender, TextNeededEventArgs e)
{
        CategoricalDataPoint dataPoint1 = e.Points[0].DataPoint as CategoricalDataPoint;
        CategoricalDataPoint dataPoint2 = e.Points[1].DataPoint as CategoricalDataPoint;
        e.Element.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
        e.Element.ForeColor = System.Drawing.Color.Blue;
 
        float difference = Math.Abs((float)dataPoint1.Value - (float)dataPoint2.Value);
 
        e.Text = string.Format("Line1: {0}\nLine2: {1}\nLine3: {2}\nLine4: {3}", dataPoint1.Category, dataPoint1.Value, dataPoint2.Value, difference);           
}

1 Answer, 1 is accepted

Sort by
1
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Apr 2017, 01:23 PM
Hello Brad, 

Thank you for writing.  

Telerik UI for WinForms provides an advanced text styling mechanism which can be applied to all Telerik WinForms controls and their elements because it enhances one of the smallest element in Telerik Presentation Framework - the text primitive. The new rich text formatting mechanism uses plain HTML tags to display formatted text such as font style, font color, font size, etc: http://docs.telerik.com/devtools/winforms/telerik-presentation-framework/html-like-text-formatting

Here is a sample code snippet demonstrating how to make each line with a different color in the trackball's label: 
private void TrackBallController_TextNeeded(object sender, TextNeededEventArgs e)
{
    CategoricalDataPoint dataPoint1 = e.Points[0].DataPoint as CategoricalDataPoint;
    CategoricalDataPoint dataPoint2 = e.Points[1].DataPoint as CategoricalDataPoint;
    e.Element.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
    e.Element.DisableHTMLRendering = false;
 
    float difference = Math.Abs((float)dataPoint1.Value - (float)dataPoint2.Value);
 
    e.Text = string.Format(@"<html><color='red'>Line1:{0}<br><color='green'>Line2:{1}<br><color='blue'>Line3:{2}<br><color='orange'>Line4:{3}",
        dataPoint1.Category, dataPoint1.Value, dataPoint2.Value, difference);          
}

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Omar
Top achievements
Rank 3
Iron
Iron
Iron
commented on 22 Mar 2022, 07:53 AM

Hi,

How to get the line colour, so I can add it within the HTML string (e.text)

 

Regards,

Omar

Dess | Tech Support Engineer, Principal
Telerik team
commented on 23 Mar 2022, 12:30 PM

Hi, Omar,

The color tag specify the ForeColor you will use for the enclosed text, e.g. 

<color='red'>Line1:{0}<br><color='green'>Line2:{1}<br>

That is why Line1 is in red and Line2 is in green. Could you please give us more details about the exact requirement that you are trying to achieve? Once we get better understanding of the precise case, we would be able to think about a suitable solution and provide further assistance. Thank you in advance.

I am looking forward to your reply.

Tags
ChartView
Asked by
Brad
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or