Bindinglist with specified colors

4 posts, 0 answers
  1. Brandon
    Brandon avatar
    4 posts
    Member since:
    Feb 2012

    Posted 16 Mar 2015 Link to this post

    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?
  2. Dimitar
    Admin
    Dimitar avatar
    1414 posts

    Posted 18 Mar 2015 Link to this post

    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Brandon
    Brandon avatar
    4 posts
    Member since:
    Feb 2012

    Posted 24 Mar 2015 in reply to Dimitar Link to this post

    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
  5. Dimitar
    Admin
    Dimitar avatar
    1414 posts

    Posted 26 Mar 2015 Link to this post

    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.

     
Back to Top