Completed
Last Updated: 12 Nov 2020 11:46 by ADMIN
Release R1 2021 (LIB 2020.3.1116)
ADMIN
Hristo
Created on: 28 Nov 2016 16:34
Category: ChartView
Type: Bug Report
1
FIX. RadChartView - the connecting lines between data points and its labels are not positioned correctly in a Cartesian series if you zoom and pan
Public Class RadForm2
    Public Sub New()
        InitializeComponent()

        AddHandler Me.RadChartView1.CreateRenderer, AddressOf radChartView1_CreateRenderer

        Me.RadChartView1.ShowSmartLabels = True
        Me.RadChartView1.ShowPanZoom = True

        Dim barSeries As New BarSeries()
        Dim barSeries1 As New BarSeries()
        Dim barSeries2 As New BarSeries()
        Dim rand As New Random()
        barSeries.DataPoints.Add(New CategoricalDataPoint(101, 0))
        barSeries1.DataPoints.Add(New CategoricalDataPoint(101, 0))
        barSeries2.DataPoints.Add(New CategoricalDataPoint(101, 0))
        For i As Integer = 1 To 9
            barSeries.DataPoints.Add(New CategoricalDataPoint(rand.[Next](100), i))
            barSeries1.DataPoints.Add(New CategoricalDataPoint(rand.[Next](100), i))
            barSeries2.DataPoints.Add(New CategoricalDataPoint(rand.[Next](100), i))
        Next

        barSeries.ShowLabels = True
        barSeries.DrawLinesToLabels = True
        barSeries1.ShowLabels = True
        barSeries1.DrawLinesToLabels = True
        barSeries2.ShowLabels = True
        barSeries2.DrawLinesToLabels = True

        Me.RadChartView1.Series.Add(barSeries)
        Me.RadChartView1.Series.Add(barSeries1)
        Me.RadChartView1.Series.Add(barSeries2)
    End Sub

    Private Sub radChartView1_CreateRenderer(sender As Object, e As ChartViewCreateRendererEventArgs)
        'e.Renderer = New CustomCartesianRenderer(TryCast(e.Area, CartesianArea))
    End Sub
End Class


Workaround: Create a custom renderer
Public Class CustomCartesianRenderer
    Inherits CartesianRenderer
    Public Sub New(area As CartesianArea)
        MyBase.New(area)
    End Sub

    Protected Overrides Sub Initialize()
        MyBase.Initialize()

        For i As Integer = 0 To Me.DrawParts.Count - 1
            Dim labelPart As BarLabelElementDrawPart = TryCast(Me.DrawParts(i), BarLabelElementDrawPart)
            If labelPart IsNot Nothing Then
                Me.DrawParts(i) = New CustomBarLabelElementDrawPart(DirectCast(labelPart.Element, BarSeries), Me)
            End If
        Next
    End Sub
End Class

Public Class CustomBarLabelElementDrawPart
    Inherits BarLabelElementDrawPart
    Public Sub New(owner As ChartSeries, renderer As IChartRenderer)
        MyBase.New(owner, renderer)
    End Sub

    Public Overrides Sub Draw()
        Dim graphics As Graphics = TryCast(Me.Renderer.Surface, Graphics)
        Dim cartesianSeries As CartesianSeries = TryCast(Me.Element, CartesianSeries)
        If cartesianSeries IsNot Nothing Then
            Dim area As CartesianArea = DirectCast(cartesianSeries.[GetType]().GetField("area", BindingFlags.Instance Or BindingFlags.NonPublic).GetValue(cartesianSeries), CartesianArea)
            Dim clipRect As RectangleF = DirectCast(area.[GetType]().GetMethod("GetCartesianClipRect", BindingFlags.Instance Or BindingFlags.NonPublic).Invoke(area, New Object() {}), RectangleF)

            graphics.SetClip(clipRect)
        End If

        MyBase.Draw()

        graphics.ResetClip()
    End Sub

    Protected Overrides Function GetLineStart(label As LabelElement, point As DataPointElement, isSmartLabel As Boolean) As PointF
        Dim lineStart As PointF = MyBase.GetLineStart(label, point, isSmartLabel)

        Dim x As Single = CSng(TryCast(Me.Element.View, IChartView).PlotOriginX)
        Dim y As Single = CSng(TryCast(Me.Element.View, IChartView).PlotOriginY)

        lineStart.X += x
        lineStart.Y += y

        Return lineStart
    End Function

    Protected Overrides Function GetLineEnd(label As LabelElement, point As DataPointElement, isSmartLabel As Boolean) As PointF
        Dim lineEnd As PointF = MyBase.GetLineEnd(label, point, isSmartLabel)

        If Not isSmartLabel Then
            Dim x As Single = CSng(TryCast(Me.Element.View, IChartView).PlotOriginX)
            Dim y As Single = CSng(TryCast(Me.Element.View, IChartView).PlotOriginY)
            lineEnd.X += x
            lineEnd.Y += y
        End If

        Return lineEnd
    End Function
End Class
0 comments