Problems while assigning colors in tColorGridSeries

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Jan
Newbie
Newbie
Posts: 24
Joined: Fri Nov 15, 2002 12:00 am
Location: Germany

Problems while assigning colors in tColorGridSeries

Post by Jan » Mon Dec 17, 2007 12:02 pm

Hello!

I have a problem when i try to assign new colors to a tColorGridSeries during runtime (Delphi 7, TeeChart 6.0 VCL/CLX). The code below tries to simulate a result array of a much larger project for finding specific regions on DNA strand. The example requires a TChart on the form and two buttons with their ButtonClick events.

My data are integers in a range of 0 to WindowSize (in the code below a constant); this means (WindowSize + 1) different colors. It is neccessary that 0 values are plotted in black, while values of WindowSize are displayed in white.

Now i urgently need to create an adjustable grayscale palette (dragging the black values up to a certain data value, or the white values down to a certain value, range from (0 to LowerLimit) is completely black and (UpperLimit to WindowSize) is completely white while the remaining steps are grayscale) but i already fail with the basic palette setup...

Maybe i did not understand the use of the palette (what is most likely), but there are a few things that appear strange to me:

- The two colors with the highest index number (in the case with a WindowSize of 7 the numbers 6 and 7) always seem to have the same color, regardless from any definition. This is not by default. It only happens when i call the UpdateColor procedure via Button1, although i do not understand where i made the mistake. It seems as if this happens in the component (can also sometimes be produced by changing a single color).

- Why does the ClearPalette command not work, when the lines prior to this command are missing?

- With Button2 i expected to assign the red color to all cells with a y-value of zero. The use must be somewhat different, i suppose....?

- Is it neccessary to have the complete definitions repeated in the UpdateColors procedure (PaletteSteps, UsePalette, etc...) ?


Maybe someone who can help me? I have been working much longer on the calculation algorithms than expected and hoped now to have a quick, comfortable and easy to use display method with the TeeChart component. T
he problem is that i need a high discriminatory power between the colors for the different values (not two colors being the same), as the emerging patterns are sometimes hard to read...


Thanks and greetings from ><)))°> Town, Germany

Jan

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, TeeProcs, TeEngine, Chart, TeeSurfa, StdCtrls;

Const WindowSize = 7;
      UpperLimit = 7;
      LowerLimit = 0;
      
type
  TForm1 = class(TForm)
    Chart1: TChart;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    Procedure UpdateColors;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



Procedure tForm1.UpdateColors;
var t         : Integer;
    NumSteps  : Integer;
    aColStep  : Byte;
    aColor    : Byte;
Begin
   NumSteps := WindowSize + 1;

  (Chart1.Series[0] as TColorGridSeries).UseColorRange := False ;
  (Chart1.Series[0] as TColorGridSeries).UsePalette    := True;
  (Chart1.Series[0] as TColorGridSeries).PaletteSteps  := NumSteps;
  (Chart1.Series[0] as TColorGridSeries).PaletteStep   := 1;
  (Chart1.Series[0] as TColorGridSeries).UsePaletteMin := True;
  (Chart1.Series[0] as TColorGridSeries).PaletteMin    := 0 ;

  (Chart1.Series[0] as TColorGridSeries).ClearPalette;

  aColor   := 0;
  aColStep := Trunc (255 / NumSteps);

  For t := 0 to NumSteps - 1 do
  Begin
    (Chart1.Series[0] as TColorGridSeries).AddPalette (t, RGB (aColor, aColor, aColor));
    aColor := aColor + aColStep;
  end;
end;


procedure TForm1.FormCreate(Sender: TObject);
Var x    : Integer;
    z    : Integer;
    aVal : Integer;
begin
  Chart1.View3D := False;
  CHart1.Legend.Visible := True;
  Chart1.Legend.Symbol.Squared := True;

  Chart1.AddSeries (tColorGridSeries.Create (Chart1));

  (Chart1.Series[0] as TColorGridSeries).UseColorRange := False ;
  (Chart1.Series[0] as TColorGridSeries).UsePalette    := True;
  (Chart1.Series[0] as TColorGridSeries).PaletteSteps  := WindowSize+1;
  (Chart1.Series[0] as TColorGridSeries).PaletteStep   := 1;
  (Chart1.Series[0] as TColorGridSeries).UsePaletteMin := True;
  (Chart1.Series[0] as TColorGridSeries).PaletteMin    := 0 ;

  For x := 0 to 30 do
  Begin
    For z := 0 to 30 do
    Begin
      aVal := Round (Random (WindowSize+1));
      (Chart1.Series[0] as TColorGridSeries).AddXYZ (x, aVal, z);
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  UpdateColors;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  (Chart1.Series[0] as TColorGridSeries).Palette[0].Color := clRed;
end;

end.

Pep
Site Admin
Site Admin
Posts: 3273
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Dec 27, 2007 12:24 pm

Hi Jan,
- Why does the ClearPalette command not work, when the lines prior to this command are missing?
I'm sorry, I'm not sure what you mean here, this method clears the palette entries, and must be called before to start adding new custom palette colors.
- With Button2 i expected to assign the red color to all cells with a y-value of zero. The use must be somewhat different, i suppose....?
Well, there're at least two ways to do it, one would be by changing the color of specific cells where the YValue is 0 using code like this :

Code: Select all

procedure TForm1.BitBtn2Click(Sender: TObject);
var i : integer;
begin
  (Chart1.Series[0] as TColorGridSeries).Palette[0].Color := clRed;

  for i:= 0 to (Chart1.Series[0] as TColorGridSeries).Count-1 do
    if  (Chart1.Series[0] as TColorGridSeries).YValue[i] = 0 then
      (Chart1.Series[0] as TColorGridSeries).ValueColor[i]:=clred;
end;
And the other way would be reassigning the custom colors palette again setting the red color for the specific range or values.
- Is it neccessary to have the complete definitions repeated in the UpdateColors procedure (PaletteSteps, UsePalette, etc...) ?
It's not necessary, once these have been assigned you shouldn't repeat them.

Post Reply