This is a migrated thread and some comments may be shown as answers.

Possible Bug In ChartView (BarChart)

2 Answers 14 Views
This is a migrated thread and some comments may be shown as answers.
Martin Hamilton
Top achievements
Rank 1
Martin Hamilton asked on 26 Nov 2019, 04:27 PM

I think I have discovered a bug in the ChartView below is the designer and code for the user control

If you create a user control and past the code into it you should be able to replicate this;

Note: to load the chart - double-click on the chart

The first time it loads properly

The second time you double-click it - you will see that it loses its formatting.

Maybe (it's possible) that I have some conflicting line(s) of code causing this but I cannot find any conflicting code... perhaps you can test out and let me know what you think?


Here's the UserControl.vb Code

Imports Telerik.Charting
Imports Telerik.WinControls
Imports Telerik.WinControls.UI
Imports TelerikHelper

Public Class ucChartTest
    Private Sub ucChartTest_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub

#Region " ENUMS "
    Private Enum GridFields
        CustomerRefFullName = 0
        Q1 = 1
        Q2 = 2
        Q3 = 3
        Q4 = 4
        Total = 5
    End Enum
#End Region

#Region " ArrayLists "
    Private _arrCustomers As New ArrayList
    Private Sub populateCustomers()
        _arrCustomers.Add("Customer 1")
        _arrCustomers.Add("Customer 2")
        _arrCustomers.Add("Customer 3")
        _arrCustomers.Add("Customer 4")
        _arrCustomers.Add("Customer 5")
        _arrCustomers.Add("Customer 6")
        _arrCustomers.Add("Customer 7")
        _arrCustomers.Add("Customer 8")
        _arrCustomers.Add("Customer 9")
        _arrCustomers.Add("Customer 10")
    End Sub

    Private _arrQ1 As New ArrayList
    Private Sub populateQ1()
    End Sub

    Private _arrQ2 As New ArrayList
    Private Sub populateQ2()
    End Sub

    Private _arrQ3 As New ArrayList
    Private Sub populateQ3()
    End Sub

    Private _arrQ4 As New ArrayList
    Private Sub populateQ4()
    End Sub
#End Region

#Region " Quarterly Sales Distribution "
    Private Sub BuildQuarterlySalesDistribution()

            RadChartView2.ShowLegend = True
            RadChartView2.ShowTitle = False
            RadChartView2.ShowSmartLabels = True
            RadChartView2.ShowGrid = True

            RadChartView2.Area.View.Palette = KnownPalette.Warm

            RadChartView2.ChartElement.LegendElement.TitlePosition = TitlePosition.Top
            RadChartView2.ChartElement.LegendPosition = LegendPosition.Top
            RadChartView2.ChartElement.LegendElement.StackElement.Orientation = Orientation.Horizontal

            AddHandler RadChartView2.ChartElement.LegendElement.VisualItemCreating, AddressOf LegendElement_VisualItemCreating

            Dim barSeriesQ1 As New Telerik.WinControls.UI.BarSeries("Q1", "Customer")
            For i As Integer = 0 To _arrQ1.Count - 1
                barSeriesQ1.DataPoints.Add(New CategoricalDataPoint(CDbl(_arrQ1(i)), _arrCustomers(i)))
            barSeriesQ1.ShowLabels = False
            barSeriesQ1.LegendTitle = "Q1"
            barSeriesQ1.CombineMode = ChartSeriesCombineMode.Stack

            Dim barSeriesQ2 As New Telerik.WinControls.UI.BarSeries("Q2", "Customer")
            For i As Integer = 0 To _arrQ2.Count - 1
                barSeriesQ2.DataPoints.Add(New CategoricalDataPoint(CDbl(_arrQ2(i)), _arrCustomers(i)))
            barSeriesQ2.ShowLabels = False
            barSeriesQ2.LegendTitle = "Q2"
            barSeriesQ2.CombineMode = ChartSeriesCombineMode.Stack

            Dim barSeriesQ3 As New Telerik.WinControls.UI.BarSeries("Q3", "Customer")
            For i As Integer = 0 To _arrQ3.Count - 1
                barSeriesQ3.DataPoints.Add(New CategoricalDataPoint(CDbl(_arrQ3(i)), _arrCustomers(i)))
            barSeriesQ3.ShowLabels = False
            barSeriesQ3.LegendTitle = "Q3"
            barSeriesQ3.CombineMode = ChartSeriesCombineMode.Stack

            Dim barSeriesQ4 As New Telerik.WinControls.UI.BarSeries("Q4", "Customer")
            For i As Integer = 0 To _arrQ4.Count - 1
                barSeriesQ4.DataPoints.Add(New CategoricalDataPoint(CDbl(_arrQ4(i)), _arrCustomers(i)))
            barSeriesQ4.ShowLabels = False
            barSeriesQ4.LegendTitle = "Q4"
            barSeriesQ4.CombineMode = ChartSeriesCombineMode.Stack

            RadChartView2.GetArea(Of CartesianArea)().Orientation = Orientation.Horizontal
        Catch ex As Exception

        End Try
    End Sub

    Private Sub LegendElement_VisualItemCreating(sender As Object, e As LegendItemElementCreatingEventArgs)
        e.ItemElement = New CustomLegendItemElement(e.LegendItem)
    End Sub

    Private Sub RadChartView2_LegendElement_VisualItemCreating(sender As Object, e As LegendItemElementCreatingEventArgs)
        e.ItemElement = New CustomLegendItemElement(e.LegendItem)
    End Sub

    Private Sub RadChartView2_DoubleClick(sender As Object, e As EventArgs) Handles RadChartView2.DoubleClick
    End Sub

    Private Sub RadChartView2_LabelFormatting(sender As Object, e As ChartViewLabelFormattingEventArgs) Handles RadChartView2.LabelFormatting
            e.LabelElement.Font = FontSegio
            e.LabelElement.BorderColor = Color.Black
            e.LabelElement.BackColor = Color.White
            e.Series.LabelRotationAngle = 45
            Dim series As BarSeries = TryCast(e.Series, BarSeries)
            Dim dblBarChartDataPoint As Double = GetBarChartDataPointValue(RadChartView2, e)
        Catch ex As Exception

        End Try
    End Sub
#End Region

End Class


Here's the Designer Code

Partial Class ucChartTest
    Inherits System.Windows.Forms.UserControl

    'UserControl overrides dispose to clean up the component list.
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing AndAlso components IsNot Nothing Then
            End If
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Private Sub InitializeComponent()
        Dim CartesianArea1 As Telerik.WinControls.UI.CartesianArea = New Telerik.WinControls.UI.CartesianArea()
        Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
        Me.RadLabel4 = New Telerik.WinControls.UI.RadLabel()
        Me.RadChartView2 = New Telerik.WinControls.UI.RadChartView()
        CType(Me.RadLabel4, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.RadChartView2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.TableLayoutPanel1.BackColor = System.Drawing.Color.White
        Me.TableLayoutPanel1.ColumnCount = 1
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100.0!))
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20.0!))
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20.0!))
        Me.TableLayoutPanel1.Controls.Add(Me.RadLabel4, 0, 1)
        Me.TableLayoutPanel1.Controls.Add(Me.RadChartView2, 0, 2)
        Me.TableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.TableLayoutPanel1.Location = New System.Drawing.Point(0, 0)
        Me.TableLayoutPanel1.Margin = New System.Windows.Forms.Padding(0)
        Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
        Me.TableLayoutPanel1.RowCount = 3
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28.0!))
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 28.0!))
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100.0!))
        Me.TableLayoutPanel1.Size = New System.Drawing.Size(370, 374)
        Me.TableLayoutPanel1.TabIndex = 0
        Me.RadLabel4.AutoSize = False
        Me.RadLabel4.Dock = System.Windows.Forms.DockStyle.Fill
        Me.RadLabel4.Font = New System.Drawing.Font("Segoe UI Semilight", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.RadLabel4.Location = New System.Drawing.Point(0, 28)
        Me.RadLabel4.Margin = New System.Windows.Forms.Padding(0)
        Me.RadLabel4.Name = "RadLabel4"
        Me.RadLabel4.Size = New System.Drawing.Size(370, 28)
        Me.RadLabel4.TabIndex = 3
        Me.RadChartView2.AreaDesign = CartesianArea1
        Me.RadChartView2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.RadChartView2.Location = New System.Drawing.Point(3, 59)
        Me.RadChartView2.Name = "RadChartView2"
        Me.RadChartView2.ShowGrid = False
        Me.RadChartView2.Size = New System.Drawing.Size(364, 312)
        Me.RadChartView2.TabIndex = 8
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.Margin = New System.Windows.Forms.Padding(0)
        Me.Name = "ucChartTest"
        Me.Size = New System.Drawing.Size(370, 374)
        CType(Me.RadLabel4, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.RadChartView2, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub

    Friend WithEvents TableLayoutPanel1 As TableLayoutPanel
    Friend WithEvents RadLabel4 As Telerik.WinControls.UI.RadLabel
    Friend WithEvents RadChartView2 As Telerik.WinControls.UI.RadChartView
End Class

2 Answers, 1 is accepted

Sort by
Martin Hamilton
Top achievements
Rank 1
answered on 26 Nov 2019, 04:33 PM
Note: The formatting is not lost when the bars are vertical - only when the orientation is horizontal
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Nov 2019, 11:06 AM

Hello, Martin,

Following the provided code snippet, I have prepared a sample project and observed the described behavior.

According to the screenshots, it seems that the horizontal axis' range is change from [0-300] to [0-100]. The possible solution that I can suggest is after repopulating the RadChart with new BarSeries and data points, specify the LinearAxis' range. Thus, it would be always fixed: 
            RadChartView1.GetArea(Of CartesianArea)().Orientation = Orientation.Horizontal
            Dim horizontalAxis As LinearAxis = TryCast(RadChartView1.Axes(1), LinearAxis)
            horizontalAxis.Minimum = 0
            horizontalAxis.Maximum = 300

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

Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Asked by
Martin Hamilton
Top achievements
Rank 1
Answers by
Martin Hamilton
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question