Question

I have a report that uses a TChart that I am maintaining. One of the TLineSeries that gets added automatically gets assigned the color clWhite, which is too close to the background (clBtnFace).

If I change it, then the next series that gets added takes clWhite. So short of going back and changing it after all the other series are created, is there some way to tell the TChart that I don't want any of my series to be clWhite?

When a series is added to the TChart the TChart assigns it a color. I want it to not assign clWhite.

Was it helpful?

Solution

OK not one to give up easily, I did some more searching. There is a unit variable called ColorPalette of type TColorArray in the TeeProcs unit. If I find and replace white with a different color that fixes it. There may be an instance copy of it. I'll keep looking since that would be preferred.

To revert the ColorPalette back just call the unit method SetDefaultColorPalette in the same unit.

SetDefaultColorPalette; // Make sure we start with the default
ColorPalette[4] := $007FFF; // Change White to Orange
try
  // add series to the chart
finally
  SetDefaultColorPalette;  // Set it back to Default
end;

BTW, I can't accept as answer because I asked the question too, but I tested it and it works.

OTHER TIPS

Near as I can tell from the TeeCharts module; no you can't specify a color that it should not be as it ships.
You can programatically walk through all the TLineSeries entries making sure at run-time that they don't use clWhite. Say you have an array of acceptable colors clArray, you can use the following code to set the colors of each of the tLineSeries entries at run time.

procedure TForm1.setColors(aChart: TChart; aColorArray: array of TColor);
var
  chi : Integer;
  coi : Integer;
begin
  coi := low(aColorArray);
  for chi := 0 to aChart.SeriesList.Count - 1 do begin
    aChart.SeriesList[chi].Color := aColorArray[coi];
    inc(coi);
    if coi > high(aColorArray) then
      coi := low(aColorArray);
  end;
end;

procedure TForm1.FormShow(Sender: TObject);
var
  ca : array of TColor;
begin
  setLength(ca, 3);
  ca[0] := clRed;
  ca[1] := clBlue;
  ca[2] := clGreen;
  setColors(Chart1, ca);
end;

You can use the series methods ClearPalette then AddPalette to create your custom palette.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top