Formatting Trackball Labels
This article demonstrates how to customize the trackball labels text and styles. This can be achieved in the TextNeeded event of the trackball controller. This event is fired when the user hover over a particular data point with the mouse and can be used to set any styles and text, depending on your preferences.
1. You should subscribe to the TextNeeded event and add the ChartTrackballController to the chart as follows.
Add Controller
ChartTrackballController controler = new ChartTrackballController();
controler.TextNeeded += controler_TextNeeded;
radChartView1.Controllers.Add(controler);
Dim controler As New ChartTrackballController()
AddHandler controler.TextNeeded, AddressOf controler_TextNeeded
RadChartView1.Controllers.Add(controler)
2. Now, you can use the TextNeeded and change any properties you desire.
Handle TextNeeded
private Font font = new Font("Segoe Script", 12, FontStyle.Regular);
private void controler_TextNeeded(object sender, TextNeededEventArgs e)
{
e.Element.BackColor = ColorTranslator.FromHtml("#91c930");
e.Element.ForeColor = ColorTranslator.FromHtml("#bb2525");
e.Element.BorderColor = ColorTranslator.FromHtml("#00Bde7");
e.Element.Font = font;
e.Element.NumberOfColors = 1;
e.Element.BorderGradientStyle = Telerik.WinControls.GradientStyles.Solid;
CategoricalDataPoint dataPoint = e.Points[0].DataPoint as CategoricalDataPoint;
e.Text = string.Format("Category: {0}, Value: {1}", dataPoint.Category, dataPoint.Value);
}
Private font As New Font("Segoe Script", 12, FontStyle.Regular)
Private Sub controler_TextNeeded(sender As Object, e As TextNeededEventArgs)
e.Element.BackColor = ColorTranslator.FromHtml("#91c930")
e.Element.ForeColor = ColorTranslator.FromHtml("#bb2525")
e.Element.BorderColor = ColorTranslator.FromHtml("#00Bde7")
e.Element.Font = font
e.Element.NumberOfColors = 1
e.Element.BorderGradientStyle = Telerik.WinControls.GradientStyles.Solid
Dim dataPoint As CategoricalDataPoint = TryCast(e.Points(0).DataPoint, CategoricalDataPoint)
e.Text = String.Format("Category: {0}, Value: {1}", dataPoint.Category, dataPoint.Value)
End Sub
The code for getting the current data point can depend on the used series type. For example if you use scatter chart, you should use ScatterDataPoint type.