Bug in ColorGrid Legend using Palette

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
TEh
Newbie
Newbie
Posts: 6
Joined: Fri Jan 29, 2010 12:00 am

Bug in ColorGrid Legend using Palette

Post by TEh » Mon Aug 30, 2010 6:52 am

The legend shows wrong colors when using own palette

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

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Bug in ColorGrid Legend using Palette

Post by Yeray » Tue Aug 31, 2010 3:55 pm

Hi TEh,

Could you please tell us in what exact TeeChart v3.2 build can you see a legend without repeated colors in the legend with that code?
Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

TEh
Newbie
Newbie
Posts: 6
Joined: Fri Jan 29, 2010 12:00 am

Re: Bug in ColorGrid Legend using Palette

Post by TEh » Mon Sep 06, 2010 12:23 pm

Hello Yeray,

version 3.2.2763.26082

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Bug in ColorGrid Legend using Palette

Post by Narcís » Wed Sep 08, 2010 1:45 pm

Hi TEh,

Thanks for the information. I have been able to reproduce the issue here and added it (TF02015141) to the defect list to be fixed.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

TEh
Newbie
Newbie
Posts: 2
Joined: Wed Apr 21, 2010 12:00 am

Re: Bug in ColorGrid Legend using Palette

Post by TEh » Mon Nov 19, 2012 11:32 am

Hello

Apparently this bug has never been fixed or it has reappeared.

TEh
Newbie
Newbie
Posts: 2
Joined: Wed Apr 21, 2010 12:00 am

Re: Bug in ColorGrid Legend using Palette

Post by TEh » Mon Nov 19, 2012 11:41 am

By the way - If I add a new value to the series after the actual values with color.empty as color, the legend shows correct colors

ColorGrid1.Add(0, 0, 0, Color.Empty)

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Bug in ColorGrid Legend using Palette

Post by Sandra » Mon Nov 19, 2012 3:56 pm

Hello Teh,

I inform you that this bug is already fixed in build 4.1.2010.02809 (TeeChart for .NET). I have debugged your code and I find that you have made an error in next line of code:

Code: Select all

	ColorGrid1.Add(y + 1, zValues(iC), x + 1, GetPointColor(zValues(iC)))
Basically, you assign, the palette to the Grid, previously add values and at the moment to add values, it is contradictory and it causes the problem in last version of TeeChartFor.Net. If you modify the previous line of code for the next:

Code: Select all

ColorGrid1.Add(y + 1, zValues(iC), x + 1)
The code works fine.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply