Page 1 of 1

Size of items in legend

Posted: Thu Oct 04, 2007 10:11 am
by 10546846
D6Pro, Teechart 8.01

Chart with several tlineseries on, the legendstyle is set to LSseries so that I get a coloured point and a text title in the legend for for each series.

I'm drawing the series as dots of X,Y scatter plots, so no lines joining the dots. The dots are controlled with
pointer.size:=2
seriescolor:=acolor
coloreachpoint:=false;

So series-1 are red dots, series-2 is blue dots.

My problem is that the size of the dot drawn in the legend next to the series titel in the legend is linked to the pointer.size. So if i add a spin edit to adjust pointer.size the dot drawn in the legend tracks this as ewll as the dots on the chart. I want to draw the dots in the legend at a fixed size that is not affected by changing pointer.size. Something like legend.pointersize:=3;

is there a way to do this please?

cheers
Sean

Posted: Fri Oct 05, 2007 8:29 am
by yeray
Hi Sean,

I've made an example of how could you do this using an event to draw your rectangles directly to the canvas. It's similar to the demo "Symbol OnDraw":

Code: Select all

...

type

...

private
    { Private declarations }
    procedure LegendDraw(Sender: TObject; Series:TChartSeries; ValueIndex:Integer; R:TRect);

...

procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin
  for i:= 0 to 9 do
  begin
    Series1.AddXY(i,random(100));
    Series2.AddXY(i,random(100));
  end;

      Series1.Pointer.Size := 5;
      Series2.Pointer.Size := 5;

      Series1.ColorEachPoint := false;
      Series2.ColorEachPoint := false;

      Series1.SeriesColor := clRed;
      Series2.SeriesColor := clBlue;

      // Set event to display custom legend symbols:
      Chart1.Legend.Symbol.OnDraw:=LegendDraw;

end;

procedure TForm1.LegendDraw(Sender: TObject; Series:TChartSeries; ValueIndex:Integer; R:TRect);
var tmpRect : TRect;
const  extra=-2;
begin
  Chart1.Canvas.Brush.Color:=Series.Color;
  Chart1.Canvas.Pen.Color:=clBlack;

  tmpRect.Left:=R.Left;
  tmpRect.Top:=R.Top;
  tmpRect.Right:=R.Right+extra;
  tmpRect.Bottom:=R.Bottom+extra;
  Chart1.Canvas.Rectangle(tmpRect);
end;