简体   繁体   中英

Devexpress webchartcontrol how to get unlimited colors collection and store in list array

Currently I have 204 items to display as legend in webchartcontrol, my current code can only support color for around 150 items. If more than that, then error "Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index". How can i get unlimited color to be store in list array? Please guide me on this.

My Code

    Dim colors As List(Of String) = New List(Of String)()
    Dim colorNames As String() = System.Enum.GetNames(GetType(KnownColor))
    Dim whiteBrightness As Single = Color.FromKnownColor(KnownColor.NavajoWhite).GetBrightness()
    For Each colorName As String In colorNames
        Dim KnownColor As KnownColor = CType(System.Enum.Parse(GetType(KnownColor), colorName), KnownColor)
        Dim knownColorBrightness As Single = Color.FromKnownColor(KnownColor).GetBrightness()
        If (KnownColor > KnownColor.Transparent AndAlso knownColorBrightness < whiteBrightness AndAlso colorName.IndexOf("Gray") = -1) Then
            colors.Add(colorName)

        End If
    Next

   Dim lColor As Dictionary(Of String, String) = New Dictionary(Of String, String)


        Dim colorTracker As Integer = 0
        '''''''''''''''''''''''''
        lColor.Add("Remaining", "DarkGray")


        For Each dr In dt.Rows
            Dim series1 As New Series(dr("tool").ToString(), ViewType.StackedBar)
            series1.ValueScaleType = ScaleType.Numerical
            series1.Points.Add(New SeriesPoint(dr("ID").ToString(), dr("Process")))


            ' series1.ToolTipEnabled = DevExpress.Utils.DefaultBoolean.True
            'series1.ToolTipHintDataMember = dr("tooldata").ToString()
            series1.ToolTipPointPattern = "<span style='font-size:13px'>EQPID: {A} <br/> Recipe: {S} <br/> " + dr("tooldata").ToString() + "</span>"

            chart.Series.Add(series1)
            Dim myview1 As StackedBarSeriesView = CType(series1.View, StackedBarSeriesView)
            myview1.BarWidth = 0.5
            myview1.FillStyle.FillMode = FillMode.Solid



            'CHECK if same item, assigned same color, else assigned other color
            If lColor.ContainsKey(dr("tool").ToString()) Then
                series1.View.Color = Color.FromName(lColor(dr("tool").ToString()))

            Else

                \\error happens here in line series1.View.Color, there 
                 are 204 tool items, but the length returned for colors from  
                 knowncolor is 174, that is why the index 
                 error occurs.My problem is there any other properties that
                 contain unlimited color?

                series1.View.Color = Color.FromName(colors(colorTracker))
                lColor.Add(dr("tool").ToString(), colors(colorTracker))
                colorTracker = colorTracker + 1

            End If
            ''''''''''

        Next

ChartControl and WebChartControl support the Series Colorizer feature (available in v18.1 and later versions) that allows to define the Series color schema from a predefined set of keys or data source values. You should be able to use the built-in functionality instead of initializing the Series color manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM