1

I would like to get some hints on working with TeeChart TAreaSeries, and specifically on creating NOT overlapping series.

When I create two Area series on the same plot, related to the same BottomAxis and LeftAxis I get something like this:

https://skydrive.live.com/redir?resid=9966BBBE2447AA89!116&authkey=!AKm6DMvrxleX5ps

And if I scroll the plot vertically I will see these two series expanding downwards endlessly to the negative infinity (Y coordinate).

But I wonder if it is possible to 'cut' the lower part of the series at some Y point? So that I could retrieve something like this:

https://skydrive.live.com/redir?resid=9966BBBE2447AA89!115&authkey=!AGaejDREPKnPYMY

(Excuse me for the links instead of images, I don't have permission to post them due to the reputation restrictions)

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
Wrackage
  • 33
  • 5

1 Answers1

1

Yes, you can do something as in the All Features\Welcome!\Axes\Opaque zones example at the new features demo, available at TeeChart's program group, for example:

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Chart1: TChart;
    Series1: TAreaSeries;
    Series2: TAreaSeries;
    procedure FormCreate(Sender: TObject);
    procedure Series1Click(Sender: TChartSeries; ValueIndex: Integer;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Chart1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    ClipRect: TRect;
    procedure SeriesBeforeDraw(Sender: TObject);
    procedure SeriesAfterDraw(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses TeCanvas;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.BeforeDrawValues:=SeriesBeforeDraw;
  Series1.AfterDrawValues:=SeriesAfterDraw;
end;

procedure TForm1.SeriesBeforeDraw(Sender: TObject);

  Function SeriesRect(Series:TChartSeries):TRect;
  begin
    With result do
    begin
      Left:=Series.GetHorizAxis.IStartPos;
      Right:=Series.GetHorizAxis.IEndPos;
      Top:=Series.GetVertAxis.IStartPos;
      Bottom:=Series.GetVertAxis.CalcYPosValue(700);
    end;
  end;

begin
  ClipRect:=SeriesRect( Sender as TChartSeries );

  { make opaque }
  With Chart1 do
       if CanClip then
          Canvas.ClipRectangle(ClipRect);
end;

procedure TForm1.SeriesAfterDraw(Sender: TObject);
begin
  Chart1.Canvas.UnClipRectangle;
end;

procedure TForm1.Series1Click(Sender: TChartSeries; ValueIndex: Integer;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Caption:=IntToStr(ValueIndex);
end;

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (Series1.Clicked(X,Y)<>-1) then
    Chart1.CancelMouse:=not PointInRect(ClipRect,X,Y);
end;

end.

which produces this chart:

enter image description here

Narcís Calvet
  • 7,304
  • 5
  • 27
  • 47
  • Thank you for the answer, it works perfectly! However, I would like to add a remark to this approach: Despite Series1 is not visible under the Y = 700 value it still 'physically' exists there. So if I click on the seemingly empty gray area between Series1 and Series2, the Series1.OnClick event will still be triggered. I wonder if there is a way to clip Series1 both visually and 'physically'? – Wrackage Jul 23 '13 at 13:06
  • @Wrackage you're welcome. Yes, this is possible using TChart.CancelMouse property, which controls when to stop processing mouse click events. I have extended my example implementing this. – Narcís Calvet Jul 23 '13 at 13:30