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

Bindinglist with specified colors

3 Answers 56 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Brandon
Top achievements
Rank 1
Brandon asked on 16 Mar 2015, 08:05 PM
I've been attempting to use the Bindinglist with the Chartview.  That functionality works per the documentation.  My issue is specifying the color of the bar entered.

A little background on the use. Using a BarSeries in a horizontal orientation (stacked), so it looks similar to an old Windows defrag bar. This basically show my equipment status over the course of a shift (12 hour period).  Green is up, red is down, orange is idle, etc.  I had it working, then the last update to Telerik Winforms crippled the functionality.  SO I am working to redo the chartview (the way I wanted to in the beginning) with data bindng.  My issue is with the examples shown for binding a BindingList, it only shows how to specify the value and category name.  Is there a way to specify the color for each entry in the BindingList?

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 18 Mar 2015, 12:21 PM
Hello Brandon,

Thank you for contacting us.

I have prepared a small sample project that shows how you can use the colors stored in the business object in the chart. The example uses the LabelFormatting event to set the colors depending on the business object

I hope this will be useful.

Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brandon
Top achievements
Rank 1
answered on 24 Mar 2015, 06:16 PM
So I have modified this to work in my VB.Net application, however, I am still having an issue.

I am using a combinemode of Stacked in Horizontal, so it looks like an expanding bar from one side of the screen to the other.  However, it will only accept the initial color.  Any color after that point is ignored.  So I am creating a new series, assigning it a color according to your example and add 

       oStatusList.Add(New Status(100, "Series") With {.barColor = cColor})

        Dim barSeria As New BarSeries("Value", "Series")
        ShiftTimeline.Series.Add(barSeria)

        barSeria.DataSource = oStatusList
        barSeria.ValueMember = "Value"
        barSeria.ValueMember = "Series"

        Dim horizontalAxis As LinearAxis = TryCast(barSeria.Axes(1), LinearAxis)
        horizontalAxis.Maximum = 720      

        Dim combineMode As ChartSeriesCombineMode = ChartSeriesCombineMode.Stack

        For i As Integer = 0 To ShiftTimeline.Series.Count - 1
            ShiftTimeline.GetSeries(Of BarSeries)(i).CombineMode = combineMode
        Next

        ShiftTimeline.GetArea(Of CartesianArea)().Orientation = Orientation.Horizontal
0
Dimitar
Telerik team
answered on 26 Mar 2015, 03:42 PM
Hello Brandon,

Thank you for writing back.

It appears that in order the formatting event to fire after the color is changed the labels must have some text. The text displaying can be avoided by setting the ForeColor of the label text:
Private Sub radChartView1_LabelFormatting(ByVal sender As Object, ByVal e As ChartViewLabelFormattingEventArgs)
    e.LabelElement.Text = "i"
 
    Dim element As CategoricalPointElement = CType(e.LabelElement.Parent, CategoricalPointElement)
    Dim myObject = TryCast(element.DataPoint.DataItem, MyCustomObject)
    e.LabelElement.ForeColor = myObject.barColor
    element.BackColor = myObject.barColor
End Sub

Then, you can change the color like this:
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    myList(1).barColor = Color.Black
    myList1(3).barColor = Color.Black
 
    radChartView1.ChartElement.Invalidate()
End Sub

Let me know if you have any additional questions.
 
Regards,
Dimitar
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
ChartView
Asked by
Brandon
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Brandon
Top achievements
Rank 1
Share this question
or