Background grid as dots at major axes?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
JerryB123
Newbie
Newbie
Posts: 2
Joined: Fri Dec 21, 2012 12:00 am

Background grid as dots at major axes?

Post by JerryB123 » Fri Aug 16, 2013 9:01 pm

Hello,

How would I get a TSeriesChart to display the background grid as single dots where the major tickmarks of the bottom and left axes would cross? (So the background would have uniformly spaced dots which would coincide with the major ticks on the left and bottom axes.)

I have searched through this newsgroup and the web, but have not found the answer to this.

Thank you.
Jerry B.

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

Re: Background grid as dots at major axes?

Post by Yeray » Tue Aug 20, 2013 11:12 am

Hi Jerry,

If I understand correctly what you mean, I think the easiest way to do it is using SmallDots with GDI:

Code: Select all

uses Series, TeCanvas;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Canvas:=TTeeCanvas3D.Create;
  Chart1.View3D:=false;

  Chart1.AddSeries(TLineSeries).FillSampleValues;

  Chart1.Draw;
  with Chart1.Axes.Left.Grid do
  begin
    Style:=psDot;
    SmallDots:=true;
    SmallSpace:=Abs(Chart1.Axes.Bottom.Items[0].LabelPos-Chart1.Axes.Bottom.Items[1].LabelPos)-1;
  end;

  Chart1.Axes.Bottom.Grid.Visible:=false;
end;
However, the above doesn't work for GDI+ and won't probably work as you want if you scroll or zoom in the chart. A more accurate but complex alternative would be using custom drawing techniques at OnBeforeDrawSeries event:

Code: Select all

uses Series;

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

  Chart1.AddSeries(TLineSeries).FillSampleValues;

  Chart1.Axes.Left.Grid.Visible:=false;
  Chart1.Axes.Bottom.Grid.Visible:=false;
end;

procedure TForm1.Chart1BeforeDrawSeries(Sender: TObject);
var bIndex, lIndex, tmpX, tmpY: Integer;
begin
  with Chart1.Canvas do
  begin
    Pen.Color:=Chart1.Axes.Left.Grid.Color;
     for bIndex:=0 to Chart1.Axes.Bottom.Items.Count-1 do
     begin
       tmpX:=Chart1.Axes.Bottom.Items[bIndex].LabelPos;
       for lIndex:=0 to Chart1.Axes.Left.Items.Count-1 do
       begin
         tmpY:=Chart1.Axes.Left.Items[lIndex].LabelPos;
         Ellipse(tmpX-1, tmpY-1, tmpX+1, tmpY+1);
       end;
     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

JerryB123
Newbie
Newbie
Posts: 2
Joined: Fri Dec 21, 2012 12:00 am

Re: Background grid as dots at major axes?

Post by JerryB123 » Wed Aug 21, 2013 12:14 pm

That does it.

Thank you.
Jerry B.

Post Reply