is it possible to perform HTML formatting on the LegendItem.Title

1 Answer 78 Views
ChartView
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
Martin Hamilton asked on 19 May 2022, 02:52 PM

I have tried to do this in a few places... but perhaps this is not supported

I'd like to be able to apply HTML formatting to the LegendItem Title so that when the  (Datapoint.LegendTitle) in the LabelFormatting routine causes the title to have html applied.

    Private Sub LegendElement_VisualItemCreating(sender As Object, e As LegendItemElementCreatingEventArgs)
        e.ItemElement = New CustomLegendItemElement(e.LegendItem)
        e.LegendItem.Title = "<html><span><font=Arial><Color=White><size=18>" & e.LegendItem.Title & "</span></html>"
        e.ItemElement.Font = FontSegio14
    End Sub

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 May 2022, 03:14 PM

Hello, Martin, 

I have prepared a sample code snippet demonstrating how to enable HTML-like text formatting for the chart legend items:

    Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        Dim spy As New RadControlSpyForm()
        spy.Show()
        AddHandler Me.RadChartView1.ChartElement.LegendElement.VisualItemCreating, AddressOf LegendElement_VisualItemCreating
        Me.RadChartView1.ShowLegend = True
        Me.RadChartView1.LegendTitle = "Legend"

        Dim barSeries As New Telerik.WinControls.UI.BarSeries("Performance", "RepresentativeName")
        barSeries.LegendTitle = "Q1"
        barSeries.DataPoints.Add(New CategoricalDataPoint(177, "Harley"))
        barSeries.DataPoints.Add(New CategoricalDataPoint(128, "White"))
        barSeries.DataPoints.Add(New CategoricalDataPoint(143, "Smith"))
        barSeries.DataPoints.Add(New CategoricalDataPoint(111, "Jones"))
        barSeries.DataPoints.Add(New CategoricalDataPoint(118, "Marshall"))
        Me.RadChartView1.Series.Add(barSeries)
        Dim barSeries2 As New Telerik.WinControls.UI.BarSeries("Performance", "RepresentativeName")
        barSeries2.LegendTitle = "Q2"
        barSeries2.DataPoints.Add(New CategoricalDataPoint(153, "Harley"))
        barSeries2.DataPoints.Add(New CategoricalDataPoint(141, "White"))
        barSeries2.DataPoints.Add(New CategoricalDataPoint(130, "Smith"))
        barSeries2.DataPoints.Add(New CategoricalDataPoint(88, "Jones"))
        barSeries2.DataPoints.Add(New CategoricalDataPoint(109, "Marshall"))
        Me.RadChartView1.Series.Add(barSeries2)
    End Sub

    Private Sub LegendElement_VisualItemCreating(sender As Object, e As LegendItemElementCreatingEventArgs)
        e.ItemElement = New LegendItemElement(e.LegendItem)
        e.LegendItem.Title = "<html><span><font=Arial><Color=Red><size=18>" & e.LegendItem.Title & "</span></html>"
        e.ItemElement.DisabledTextRenderingHint = False
    End Sub

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

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