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

ChartView bug?

1 Answer 78 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Viktor
Top achievements
Rank 1
Viktor asked on 25 Jan 2021, 08:38 AM

Hi,

According to this thread: https://www.telerik.com/forums/how-to-force-series-color

Children collection should be used to set specific color for pie element

radChartView1.Series[0].Children[0].BackColor = Color.Red;

However, I noticed "strange" behavior in data bound mode: As soon as reference to Children is made labels are not shown.

You can see this behavior in sample below:

Uncomment any of 2 lines below and you can see labels are not there

'series.Children(i).BackColor = Color.AntiqueWhite
'Dim point = CType(series.Children(i), DataPointElement)

Simple form with load event:

Imports Telerik.WinControls.UI
 
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim chart = New RadChartView()
        chart.AreaType = ChartAreaType.Pie
        Me.Controls.Add(chart)
        Dim series = New PieSeries("ValueMember", "CategoryMember")
 
        Dim dataSource = New List(Of DataItem)
        dataSource.Add(New DataItem("10", "test1"))
        dataSource.Add(New DataItem("10", "test2"))
        dataSource.Add(New DataItem("10", "test3"))
        dataSource.Add(New DataItem("10", "test4"))
        series.ShowLabels = True
        series.DataSource = dataSource
 
        For i = 0 To series.Children.Count - 1
            'series.Children(i).BackColor = Color.AntiqueWhite
            'Dim point = CType(series.Children(i), DataPointElement)
        Next
 
        chart.Series.Add(series)
    End Sub
 
End Class

And data object:

Public Class DataItem
    Public Property ValueMember As String
    Public Property CategoryMember As String
 
    Public Sub New (valueM As String, categoryM As String)
        ValueMember = valueM
        CategoryMember = categoryM
    End Sub
 
End Class

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 26 Jan 2021, 02:56 PM

Hello, Victor,

The provided code is greatly appreciated.

In order to achieve a proper layout, you should first add the pie series to the Series collection of the chart, then customize the colors:

Private Sub RadForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim chart = New RadChartView()
    chart.AreaType = ChartAreaType.Pie
    Me.Controls.Add(chart)
    Dim series = New PieSeries("ValueMember", "CategoryMember")

    Dim dataSource = New List(Of DataItem)
    dataSource.Add(New DataItem("10", "test1"))
    dataSource.Add(New DataItem("10", "test2"))
    dataSource.Add(New DataItem("10", "test3"))
    dataSource.Add(New DataItem("10", "test4"))
    series.ShowLabels = True
    series.DataSource = dataSource
    chart.Series.Add(series)

    For i = 0 To series.Children.Count - 1
        series.Children(i).BackColor = Color.AntiqueWhite
        Dim point = CType(series.Children(i), DataPointElement)
    Next
End Sub

I hope this helps. Should you have any other questions do not hesitate to contact me. 

Regards,
Nadya
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
Viktor
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or