Hi,
i'm trying to set/edit the legend labels of my UltraChart (Infragistics2.WebUI.UltraWebChart.v8.3 : Infragistics.WebUI.UltraWebChart) by using different techniques, but none of them seems to work.
The chart type i'm using is the StackColumnChart (2D).
I'm using the NumericDataPoint class to fill the chart (no dataset):
...
series.Points.Add(New NumericDataPoint(5.0, labelId, False))
chart.Series.Add(series)
This results in a legend having the same labels that where set to the data points label.
I tried to set the label by using the DrawItemEvent:
Dim handler As New Infragistics.UltraChart.Shared.Events.ChartDrawItemEventHandler(AddressOf DrawItem) AddHandler Chart.ChartDrawItem, handler
Private Sub DrawItem(ByVal sender As Object, ByVal args As Infragistics.UltraChart.Shared.Events.ChartDrawItemEventArgs) Dim _text As Text = TryCast(args.Primitive, Text) If Not _text Is Nothing AndAlso Not String.IsNullOrEmpty(_text.Path) AndAlso _text.Path.EndsWith("Legend") AndAlso Not _text.Column = -1 Then Dim labelIdAs Long = CLng(_text.Value) If _labelDictionary.ContainsKey(labelId) Then _text.Value = _labelDictionary(labelId).Name End If End If End Sub
But the legend labels never appeared.
After that i tried to get it done by using the IRenderLabel interface:
....
Dim labelRenderers As New Hashtable labelRenderers.Add("CUSTOM", New LabelRenderer(_labelDictionary)) Chart.LabelHash = labelRenderers Chart.Legend.FormatString = "<CUSTOM>"
Public Class LabelRenderer Implements Infragistics.UltraChart.Resources.IRenderLabel Private _labelDictionary As IDictionary(Of Long, NamedObject) Public Sub New(ByVal labels As IDictionary(Of Long, NamedObject)) _labelDictionary = labels End Sub Public Function ToString1(ByVal context As System.Collections.Hashtable) As String Implements Infragistics.UltraChart.Resources.IRenderLabel.ToString Dim label As String = Convert.ToString(context("ITEM_LABEL")) If Not String.IsNullOrEmpty(label) Then Dim labelId As Long = CLng(label) If _labelDictionary.ContainsKey(labelId) Then label = _labelDictionary(labelId).Name End If End If Return label End Function End Class
but that did not work either. The labelRenderers ToString-Method never gets called in contrast to the DrawItem-Method which seems to work for everything else than the legend labels/primitives.
I'm totally stuck there.
Thanks in advance for any help.
I think your ChartDrawItem code will work if you use the Text.GetTextString / SetTextString methods instead of the Text.Value property.
As for the IRenderLabel stuff, it looks correct to me, and I'm not sure why it's not getting called. When I tested this out using the 8.3 release version, it worked okay and I was able to use IRenderLabel for the Legend.FormatString.
I'm having the same problem using v9.1.
All the samples about the IRenderLabel don't seem to work.
I'm trying to reverse the order of the labels and it does revert the order of the square colors but not the labels. Any ideas?
which IRenderLabel samples aren't working? have you tried using this article as a guide? http://help.infragistics.com/NetAdvantage/ASPNET/2010.2/CLR4.0/?page=Chart_Customize_Labels_Using_the_IRenderLabel_Interface.html