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

Possible Bug In ChartView (BarChart)

2 Answers 130 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
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
        populateCustomers()
        populateQ1()
        populateQ2()
        populateQ3()
        populateQ4()
    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.Clear()
        _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()
        _arrQ1.Clear()
        _arrQ1.Add(73)
        _arrQ1.Add(69)
        _arrQ1.Add(50)
        _arrQ1.Add(32)
        _arrQ1.Add(34)
        _arrQ1.Add(19)
        _arrQ1.Add(27)
        _arrQ1.Add(24)
        _arrQ1.Add(27)
        _arrQ1.Add(30)
    End Sub

    Private _arrQ2 As New ArrayList
    Private Sub populateQ2()
        _arrQ2.Clear()
        _arrQ2.Add(40)
        _arrQ2.Add(82)
        _arrQ2.Add(47)
        _arrQ2.Add(46)
        _arrQ2.Add(32)
        _arrQ2.Add(21)
        _arrQ2.Add(39)
        _arrQ2.Add(45)
        _arrQ2.Add(29)
        _arrQ2.Add(33)
    End Sub

    Private _arrQ3 As New ArrayList
    Private Sub populateQ3()
        _arrQ3.Clear()
        _arrQ3.Add(93)
        _arrQ3.Add(76)
        _arrQ3.Add(58)
        _arrQ3.Add(41)
        _arrQ3.Add(41)
        _arrQ3.Add(37)
        _arrQ3.Add(35)
        _arrQ3.Add(22)
        _arrQ3.Add(39)
        _arrQ3.Add(21)
    End Sub

    Private _arrQ4 As New ArrayList
    Private Sub populateQ4()
        _arrQ4.Clear()
        _arrQ4.Add(75)
        _arrQ4.Add(39)
        _arrQ4.Add(31)
        _arrQ4.Add(27)
        _arrQ4.Add(30)
        _arrQ4.Add(51)
        _arrQ4.Add(10)
        _arrQ4.Add(13)
        _arrQ4.Add(6)
        _arrQ4.Add(16)
    End Sub
#End Region

#Region " Quarterly Sales Distribution "
    Private Sub BuildQuarterlySalesDistribution()
        Try
            RadChartView2.Series.Clear()

            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)))
            Next
            barSeriesQ1.ShowLabels = False
            barSeriesQ1.LegendTitle = "Q1"
            barSeriesQ1.CombineMode = ChartSeriesCombineMode.Stack
            RadChartView2.Series.Add(barSeriesQ1)

            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)))
            Next
            barSeriesQ2.ShowLabels = False
            barSeriesQ2.LegendTitle = "Q2"
            barSeriesQ2.CombineMode = ChartSeriesCombineMode.Stack
            RadChartView2.Series.Add(barSeriesQ2)

            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)))
            Next
            barSeriesQ3.ShowLabels = False
            barSeriesQ3.LegendTitle = "Q3"
            barSeriesQ3.CombineMode = ChartSeriesCombineMode.Stack
            RadChartView2.Series.Add(barSeriesQ3)

            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)))
            Next
            barSeriesQ4.ShowLabels = False
            barSeriesQ4.LegendTitle = "Q4"
            barSeriesQ4.CombineMode = ChartSeriesCombineMode.Stack
            RadChartView2.Series.Add(barSeriesQ4)


            RadChartView2.GetArea(Of CartesianArea)().Orientation = Orientation.Horizontal
            Application.DoEvents()
        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
        BuildQuarterlySalesDistribution()
    End Sub

    Private Sub RadChartView2_LabelFormatting(sender As Object, e As ChartViewLabelFormattingEventArgs) Handles RadChartView2.LabelFormatting
        Try
            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

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class ucChartTest
    Inherits System.Windows.Forms.UserControl

    'UserControl overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()>
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        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.
    <System.Diagnostics.DebuggerStepThrough()>
    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()
        Me.TableLayoutPanel1.SuspendLayout()
        CType(Me.RadLabel4, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.RadChartView2, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'TableLayoutPanel1
        '
        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
        '
        'RadLabel4
        '
        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.RadLabel4.Text = "QUARTERLY SALES DISTRIBUTION"
        '
        'RadChartView2
        '
        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
        '
        'ucChartTest
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.Controls.Add(Me.TableLayoutPanel1)
        Me.Margin = New System.Windows.Forms.Padding(0)
        Me.Name = "ucChartTest"
        Me.Size = New System.Drawing.Size(370, 374)
        Me.TableLayoutPanel1.ResumeLayout(False)
        CType(Me.RadLabel4, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.RadChartView2, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    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
0
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
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
0
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
            Application.DoEvents()


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

Regards,
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.
Tags
ChartView
Asked by
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or