Page 1 of 1

Background grid as dots at major axes?

Posted: Fri Aug 16, 2013 9:01 pm
by 16564517
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.

Re: Background grid as dots at major axes?

Posted: Tue Aug 20, 2013 11:12 am
by yeray
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;

Re: Background grid as dots at major axes?

Posted: Wed Aug 21, 2013 12:14 pm
by 16564517
That does it.

Thank you.
Jerry B.