Search code examples
delphidelphi-7vclteechart

Is it possible to 'clip' the lower part of TAreaSeries?


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)


Solution

  • 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