Page 1 of 1

Some questions about TGDIPlusCanvas

Posted: Fri Nov 29, 2013 6:45 am
by 16562051
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.

Re: Some questions about TGDIPlusCanvas

Posted: Fri Nov 29, 2013 7:07 am
by 16562051
The question 1 is more important because it actually makes visual comparison of OHLC prices more harder for our customers.

Re: Some questions about TGDIPlusCanvas

Posted: Fri Nov 29, 2013 9:48 am
by narcis
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.

Re: Some questions about TGDIPlusCanvas

Posted: Mon Dec 02, 2013 2:46 am
by 16562051
Hi,

How can I make TCandleSeries to be as sharp as TBarSeries does while AntiAlias:=True?

Re: Some questions about TGDIPlusCanvas

Posted: Mon Dec 02, 2013 11:16 am
by narcis
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.

Re: Some questions about TGDIPlusCanvas

Posted: Tue Dec 03, 2013 7:22 am
by 16562051
This is really helpful, thanks!