locked
Changing colors RRS feed

  • Question

  • Hi! i'm making a pie chart and i do it by code.

    i know how to include my own pallete of colors, for example:  

    Dim colorSet() As Drawing.Color = {Drawing.Color.Blue, Drawing.Color.Gray, Drawing.Color.BlueViolet, Drawing.Color.Peru, Drawing.Color.Red, Drawing.Color.Yellow}
    
    Chart.Palette = ChartColorPalette.None
    Chart.PaletteCustomColors = colorSet
    

    Well, i make the datapoint like that:

     If (okOn <> 0) Then
      Series.Points.AddXY("OkOn: " & okOn, okOn)
     End If
     If (okOff <> 0) Then
      Series.Points.AddXY("OkOff: " & okOff, okOff)
     End If ...
    

    If On = 0 the chart don't draw this point but the color i assigned at firs point is used to the second point and i don't want this. Can i assign colors dinamically? I try this but it doesn't work:

     If (On <> 0) Then
      Series.Points.AddXY("On: " & On, On)
      Series.Points.Item(0).Color = Drawing.Color.Blue
     End If
     If (Off <> 0) Then
      Series.Points.AddXY("Off: " & Off, Off)
      Series.Points.Item(0).Color = Drawing.Color.Gray
     End If
    • Edited by aty88 Tuesday, May 11, 2010 10:07 AM
    Tuesday, May 11, 2010 9:43 AM

Answers

  • I solutioned it! i don't know if this is the best way or the most elegant but it works:

    I declare the array whitout values: Dim colorSet(8) As Drawing.Color

    in each 'if' i include a new value in array:

    Dim num As Integer = 0

    If

     

    (On <> 0) Then

    Series.Points.AddXY(

    "On: " & On, On)

    colorSet(num) = Drawing.Color.Blue

    num = num + 1

     

    End If

    ...

    • Marked as answer by aty88 Tuesday, May 11, 2010 10:07 AM
    Tuesday, May 11, 2010 10:05 AM