legen symbol pen width

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Sean Murphy
Newbie
Newbie
Posts: 19
Joined: Thu Sep 27, 2007 12:00 am
Location: UK
Contact:

legen symbol pen width

Post by Sean Murphy » Mon Oct 12, 2009 1:15 pm

Tchart Pro vsn 8.06

Chart with a few Tlineseries drawing X,Y graphs
I have lineseries.pointer.size = 1, lineseries.pointer.visible=false
so the graph draws just a linebetween the x,y points, the actual points not being displayed on chart

If I alter lineseries.pen.width it alters thw width of the line connecting the x,y points, which is the effect I want.

However, I have the legend set to show each lineseries so there is a checkbox, the series name, and between the checkbox and series name there
is a short line the same colour as the series colour configured. This is default Tchart display, I'm not using custom draw for legend.
When I alter lineseries.pen.width it also alters the width of the line that is shown in the legend, my question is can I prevent this?
I want legend line width to be fixed at 3, but user to be able to set grap line width to different settings

thanks
Sean

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

Re: legen symbol pen width

Post by Yeray » Wed Oct 14, 2009 10:36 am

Hi Sean,

I'm afraid that the pens drawn in the legend symbols are linked to the series, so there isn't an option to change them. However, you can use the legend's symbol's event OnDraw to customize them. Something similar to the demo at All Features/Welcome !/Miscellaneous/Legend/Symbol OnDraw

Code: Select all

uses series, TeCanvas;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  Chart1.View3D := false;

  for i:=0 to 4 do
  begin
    Chart1.AddSeries(TLineSeries.Create(self));
    Chart1[i].FillSampleValues();
  end;

  Chart1.Legend.Symbol.OnDraw:=LegendDraw;
end;

procedure TForm1.LegendDraw(Sender: TObject; Series: TChartSeries;
  ValueIndex: Integer; R: TRect);
var YPos: Integer;
begin
  with Chart1.Canvas do
  begin
    if Chart1.Legend.Symbol.Pen.Visible then
    begin
      //clear the symbol
      Brush.Style:=bsSolid;
      Pen.Style:=psClear;
      Rectangle(R,0);

      //draw the new symbol
      Pen.Style:=psSolid;
      Pen.Color:=Series.Color;
      Pen.Width:=3;
      YPos:=(R.Bottom-R.Top) div 2 + R.Top;
      Line(R.Left,YPos,R.Right,YPos);
    end;
  end;
end;
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

Sean Murphy
Newbie
Newbie
Posts: 19
Joined: Thu Sep 27, 2007 12:00 am
Location: UK
Contact:

Re: legen symbol pen width

Post by Sean Murphy » Fri Oct 16, 2009 6:26 am

thanks Yeray, I'll try that way.
Sean

Post Reply