The example below runs ok with version 3.2 showing in legend colors red, yellow, white, turquoise and blue.
With the latest 4.1 version the colors shown are wrong (some colors shown twice)
To use the example just create a form test.vb in windows.forms vb project referencing the appropriate teechart version
and replace the contents of created test.vb with code below.
Code: Select all
Imports Steema.TeeChart
Public Class test
Private zValues(23) As Double
Private ScaleColors() As Color
Private ScalePoints() As Double
Private iRangeCount As Integer = 5
Private dRMin As Double
Private dRMax As Double
Private dTarget As Double
Private dColorStep As Double
Private TChart1 As New Steema.TeeChart.TChart
Private ColorGrid1 As New Steema.TeeChart.Styles.ColorGrid
Private Sub test_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TChart1.Aspect.View3D = False
ColorGrid1.IrregularGrid = False
ColorGrid1.ShowInLegend = True
ColorGrid1.UsePalette = True
ColorGrid1.UseColorRange = False
TChart1.Legend.Series = ColorGrid1
TChart1.Legend.MaxNumRows = 5
TChart1.Legend.LegendStyle = LegendStyles.Palette
TChart1.Series.Add(ColorGrid1)
Me.Controls.Add(TChart1)
SetData()
End Sub
Private Sub SetData()
Dim iC As Integer
Dim iAdd As Integer = 0
Dim rG As New System.Random
ColorGrid1.ClearPalette()
ColorGrid1.Clear()
' create random data
iC = 0
dRMin = Double.MaxValue
dRMax = Double.MinValue
For x As Integer = 0 To 3
For y As Integer = 0 To 5
zValues(iC) = rG.NextDouble
If zValues(iC) < dRMin Then dRMin = zValues(iC)
If zValues(iC) > dRMax Then dRMax = zValues(iC)
iC += 1
Next
Next
SetScalePointsAndScaleColors()
' Add palettes
For iC = 0 To iRangeCount - 2
ColorGrid1.AddPalette(ScalePoints(iC), ScaleColors(iC + iAdd))
If iAdd = 0 AndAlso iC < iRangeCount - 2 Then
If ScalePoints(iC + 1) > dTarget Then
iAdd = 1
ColorGrid1.AddPalette(dTarget, ScaleColors(iC + iAdd))
End If
End If
Next
' Add data using palette colors
iC = 0
For x As Integer = 0 To 3
For y As Integer = 0 To 5
ColorGrid1.Add(y + 1, zValues(iC), x + 1, GetPointColor(zValues(iC)))
iC += 1
Next
Next
End Sub
Private Sub SetScalePointsAndScaleColors()
' divide value range into desired number of subranges
dColorStep = (dRMax - dRMin) / CDbl(iRangeCount)
ReDim ScalePoints(iRangeCount - 2)
SetStandardScalePoints()
dTarget = (dRMax + dRMin) / 2.0
ReDim ScaleColors(iRangeCount - 1)
SetStandardScaleColors()
End Sub
Private Sub SetStandardScalePoints()
For i As Integer = 0 To iRangeCount - 2
ScalePoints(i) = dRMin + dColorStep * CDbl(i + 1)
Next
End Sub
Private Sub SetStandardScaleColors()
Dim iAlpha As Integer = 255
ScaleColors(0) = Color.FromArgb(iAlpha, 0, 0, 240)
ScaleColors(1) = Color.FromArgb(iAlpha, 0, 240, 240)
ScaleColors(2) = Color.FromArgb(iAlpha, 240, 240, 240)
ScaleColors(3) = Color.FromArgb(iAlpha, 240, 240, 0)
ScaleColors(4) = Color.FromArgb(iAlpha, 240, 0, 0)
End Sub
Private Function GetPointColor(ByVal dVal As Double) As Color
Dim retCol As Color = Color.Black
Dim iIndex As Integer
Try
iIndex = CInt(Math.Floor(Math.Abs(dVal - dRMin) / dColorStep))
If iIndex > iRangeCount - 1 Then
iIndex = iRangeCount - 1
End If
If dVal > dTarget Then
If dVal > ScalePoints(iIndex - 1) Then
retCol = ScaleColors(iIndex)
Else
retCol = ScaleColors(iIndex - 1)
End If
Else
If dVal < ScalePoints(iIndex) Then
retCol = ScaleColors(iIndex)
Else
retCol = ScaleColors(iIndex + 1)
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Debug.WriteLine(dVal.ToString & " -> " & iIndex.ToString)
Return retCol
End Function
End Class