Some questions about TGDIPlusCanvas

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
sswang
Newbie
Newbie
Posts: 24
Joined: Wed Mar 28, 2012 12:00 am

Some questions about TGDIPlusCanvas

Post by sswang » Fri Nov 29, 2013 6:45 am

Hi,

I'm trying to upgrade my project from TTeeCanvas3D to TGDIPlusCanvas for more eye candy.
Currently there are 2 noticeable differences that I'd like to ask for advice.

1. How can I have a sharp TCandleSeries in TGDIPlusCanvas? just like TBarSeries does. They are all about rectangle and straight line after all.
2. 1 pixel setting is not presenting any more. Can I have it back? they are all straight lines though.
Attachments
error.png
error.png (11.5 KiB) Viewed 9320 times

sswang
Newbie
Newbie
Posts: 24
Joined: Wed Mar 28, 2012 12:00 am

Re: Some questions about TGDIPlusCanvas

Post by sswang » Fri Nov 29, 2013 7:07 am

The question 1 is more important because it actually makes visual comparison of OHLC prices more harder for our customers.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Some questions about TGDIPlusCanvas

Post by Narcís » Fri Nov 29, 2013 9:48 am

Hi sswang,

Yes, this is possible disabling GDI+ canvas AntiAlias property, for example:

Code: Select all

  (GDIPChart.Canvas as TGDIPlusCanvas).AntiAlias:=False;
A complete example comparing identical charts in GDI+ and GDI Win32:

Code: Select all

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure SetChart(Chart: TChart);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  GDIPChart : TChart;
  GDIChart  : TChart;
begin          

  GDIPChart:=TChart.Create(Self);
  GDIPChart.Parent:=Self;
  GDIPChart.Align:=alTop;
  (GDIPChart.Canvas as TGDIPlusCanvas).AntiAlias:=False;
  SetChart(GDIPChart);

  GDIChart:=TChart.Create(Self);
  GDIChart.Parent:=Self;
  GDIChart.Align:=alBottom;
  GDIChart.Canvas:=TTeeCanvas3D.Create;
  SetChart(GDIChart);
end;

procedure TForm1.SetChart(Chart: TChart);
var
  Candle  : TCandleSeries;
begin
  Candle:=TCandleSeries.Create(Self);
  Candle.ParentChart:=Chart;
  Candle.FillSampleValues();
  Candle.Pen.Visible:=False;

  Chart.View3D:=False;
end;

end.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

sswang
Newbie
Newbie
Posts: 24
Joined: Wed Mar 28, 2012 12:00 am

Re: Some questions about TGDIPlusCanvas

Post by sswang » Mon Dec 02, 2013 2:46 am

Hi,

How can I make TCandleSeries to be as sharp as TBarSeries does while AntiAlias:=True?
Attachments
p1.png
p1.png (4.67 KiB) Viewed 9299 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Some questions about TGDIPlusCanvas

Post by Narcís » Mon Dec 02, 2013 11:16 am

Hello,

You can disable AntiAlias por TCandleSeries only, for example:

Code: Select all

procedure TForm1.Series1BeforeDrawValues(Sender: TObject);
begin
  (Chart1.Canvas as TGDIPlusCanvas).AntiAlias:=False;
end;

procedure TForm1.Series1AfterDrawValues(Sender: TObject);
begin
  (Chart1.Canvas as TGDIPlusCanvas).AntiAlias:=True;
end;
The complete example:

Code: Select all

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure SetChart(Chart: TChart);
    procedure Series1BeforeDrawValues(Sender: TObject);
    procedure Series1AfterDrawValues(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  GDIPChart : TChart;
  GDIChart  : TChart;
begin          

  GDIPChart:=TChart.Create(Self);
  GDIPChart.Parent:=Self;
  GDIPChart.Align:=alTop;
  //(GDIPChart.Canvas as TGDIPlusCanvas).AntiAlias:=False;
  SetChart(GDIPChart);

  GDIChart:=TChart.Create(Self);
  GDIChart.Parent:=Self;
  GDIChart.Align:=alBottom;
  GDIChart.Canvas:=TTeeCanvas3D.Create;
  SetChart(GDIChart);
end;

procedure TForm1.SetChart(Chart: TChart);
var
  Candle  : TCandleSeries;
begin
  Candle:=TCandleSeries.Create(Self);
  Candle.ParentChart:=Chart;
  Candle.FillSampleValues();
  Candle.Pen.Visible:=False;

  if (Chart.Canvas is TGDIPlusCanvas) then
  begin
    Candle.BeforeDrawValues:=Series1BeforeDrawValues;
    Candle.AfterDrawValues:=Series1AfterDrawValues;
  end;

  Chart.View3D:=False;
end;

procedure TForm1.Series1BeforeDrawValues(Sender: TObject);
begin
  ((Sender as TCandleSeries).ParentChart.Canvas as TGDIPlusCanvas).AntiAlias:=False;
end;

procedure TForm1.Series1AfterDrawValues(Sender: TObject);
begin
  ((Sender as TCandleSeries).ParentChart.Canvas as TGDIPlusCanvas).AntiAlias:=True;
end;


end.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

sswang
Newbie
Newbie
Posts: 24
Joined: Wed Mar 28, 2012 12:00 am

Re: Some questions about TGDIPlusCanvas

Post by sswang » Tue Dec 03, 2013 7:22 am

This is really helpful, thanks!

Post Reply