Trackball Label Text Coloring

2 posts, 0 answers
  1. Brad
    Brad avatar
    4 posts
    Member since:
    Mar 2016

    Posted 30 Mar 2017 Link to this post

    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);           
    }
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3891 posts

    Posted 03 Apr 2017 Link to this post

    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.
Back to Top