Fixed grid

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Fixed grid

Post by PoLabs » Thu Dec 24, 2009 12:31 pm

Hi,

I searched a little bit but I havent found topic on this. I centered Left and Bottom axes and I have dotted grid and 10 divisions on both sides. I would like to have fixed grid all time (even when zoomed).

This is in non-zoomed view
Image

when I zoom the grid gets offset (logical) according to axes
Image

Is it possible to somehow lock the grid (to have same view all time) and keep up the proper calculations of chart?

Thanks.

BTW: Merry Christmas and Happy new year. ;)

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

Re: Fixed grid

Post by Narcís » Thu Dec 24, 2009 2:18 pm

Hi PoLabs,
Is it possible to somehow lock the grid (to have same view all time) and keep up the proper calculations of chart?
When and how are you doing this? You could try doing it in the AfterDraw event or also adding Chart1.Draw calls in the OnZoom and OnUndoZoom to force the chart being refreshed and therefore OnAfterDraw event being fired.

If the problem persists please attach a simple example project we can run "as-is" to reproduce the problem here.
BTW: Merry Christmas and Happy new year. ;)
Thank you very much :!: Wish you a merry Christmas and the best for 2010.
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

PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Re: Fixed grid

Post by PoLabs » Mon Dec 28, 2009 8:35 am

Hi again, ;)

Well I would like to attaxch some exe but this is part of project with access restrictions. However I will try to explain to you. As I already mentioned my graph consists of left axis and bottom axis. Both axes has PositionPercent set to 50% so they are centered in chart. The grid has 10 divisions horizontaly and verticaly . When not zoomed in the grid and axes are aligned to each other but when I zoom with mouse the position of axes changes a bit (gets an offset regarding previous position) and this looks like the grid and axes are not aligned (pic 2 of previous post) any more.

What I want is to keep grid and axes always at fixed position, no matter if zoomed on unzoomed. I hope I am clear enough.

Thank you for your help.

Best Regards,
PoLabs

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

Re: Fixed grid

Post by Yeray » Mon Dec 28, 2009 12:08 pm

Hi PoLabs,

I'm not sure to understand if you want the axes to move or to be always in the center of your chart. If you want them to move with the chart scroll and zoom, I'd recommend you to use two ColorLineTools instead of the axes. Here it is an example:

Code: Select all

uses series, teetools;

procedure TForm1.FormCreate(Sender: TObject);
var Points1: TPointSeries;
    i: Integer;
    ColorLine1, ColorLine2: TColorLineTool;
begin
  Chart1.View3D:=false;

  Points1:=Chart1.AddSeries(TPointSeries.Create(self)) as TPointSeries;

  for i:=-5 to 5 do
    Points1.AddXY(i,(random*9)-5);

  with Chart1.Axes.Bottom do
  begin
    Axis.Visible:=false;
    Ticks.Visible:=false;
    TicksInner.Visible:=false;
    MinorTicks.Visible:=false;
    Items.Clear;
    for i:=-5 to 5 do
      Items.Add(i,' ');
    SetMinMax(-6,6);
  end;

  with Chart1.Axes.Left do
  begin
    Axis.Visible:=false;
    Ticks.Visible:=false;
    TicksInner.Visible:=false;
    MinorTicks.Visible:=false;
    Items.Clear;
    for i:=-5 to 5 do
      Items.Add(i,' ');
    SetMinMax(-6,6);
  end;


  ColorLine1:=Chart1.Tools.Add(TColorLineTool.Create(self)) as TColorLineTool;
  ColorLine1.Axis:=Chart1.Axes.Bottom;
  ColorLine1.Value:=0;
  ColorLine1.Pen.Color:=clRed;
  ColorLine1.Pen.Width:=2;

  ColorLine2:=Chart1.Tools.Add(TColorLineTool.Create(self)) as TColorLineTool;
  ColorLine2.Axis:=Chart1.Axes.Left;
  ColorLine2.Value:=0;
  ColorLine2.Pen.Color:=clRed;
  ColorLine2.Pen.Width:=2;
end;
If you want the axes to be always in the center of the chart:

Code: Select all

uses series;

procedure TForm1.FormCreate(Sender: TObject);
var Points1: TPointSeries;
    i: Integer;
begin
  Chart1.View3D:=false;

  Points1:=Chart1.AddSeries(TPointSeries.Create(self)) as TPointSeries;

  for i:=-5 to 5 do
    Points1.AddXY(i,(random*9)-5);

  with Chart1.Axes.Bottom do
  begin
    Axis.Color:=clRed;
    PositionPercent:=50;
    Ticks.Visible:=false;
    TicksInner.Visible:=false;
    MinorTicks.Visible:=false;
    Items.Clear;
    for i:=-5 to 5 do
      Items.Add(i,' ');
    SetMinMax(-6,6);
  end;

  with Chart1.Axes.Left do
  begin
    Axis.Color:=clRed;
    PositionPercent:=50;
    Ticks.Visible:=false;
    TicksInner.Visible:=false;
    MinorTicks.Visible:=false;
    Items.Clear;
    for i:=-5 to 5 do
      Items.Add(i,' ');
    SetMinMax(-6,6);
  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

PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Re: Fixed grid

Post by PoLabs » Tue Dec 29, 2009 11:01 am

Hi,

I set

Code: Select all

  
with Chart1.Axes.Bottom do
  begin
    Axis.Color:=clRed;
    PositionPercent:=50;
    Ticks.Visible:=false;
    TicksInner.Visible:=false;
    MinorTicks.Visible:=false;
    Items.Clear;
    for i:=-5 to 5 do
      Items.Add(i,' ');
    SetMinMax(-6,6);
  end;

  with Chart1.Axes.Left do
  begin
    Axis.Color:=clRed;
    PositionPercent:=50;
    Ticks.Visible:=false;
    TicksInner.Visible:=false;
    MinorTicks.Visible:=false;
    Items.Clear;
    for i:=-5 to 5 do
      Items.Add(i,' ');
    SetMinMax(-6,6);
  end;
As I mentioned I have grif with 10 divisions verticaly and horizontaly. When I zoome I would like to keep/update zoomed rectangle to 10 divs verticaly and horizontaly soI take bottom axis min and max and divide it to 10 divs but this makes that grid and axes are not aligned (see picture 2).

Point is that on zoom I recalculate increment for grid. with increment everything is just fine but how to give a grid some offset(x,y) to align grid to axes.

Take a look at the attached video link first 5 seconds it is unzoomed stat later I zoom severla times to show you how Increment recalculation is ok but the offset of grid is changing and this occurs that grid is not aligned with axes.

So question is how to set offset of grid to align it to axes?

Link to video: http://www.sekopt.si/soundfreak/temp/grid.avi

I hope you understand my confused questions? It is so hard to make good question.

Best regards.


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

Re: Fixed grid

Post by Yeray » Tue Dec 29, 2009 4:47 pm

Hi PoLabs,

Probably it was me who didn't understand well your issue. If I understood fine now, the following example does what you are trying to do, isn't it?

Code: Select all

uses series;

procedure TForm1.FormCreate(Sender: TObject);
var i:Integer;
begin
  Chart1.View3D:=false;
  Chart1.Title.Visible:=false;

  Chart1.AddSeries(TPointSeries.Create(self));
  for i:=-4 to 4 do
    Chart1[0].AddXY(i,(random*9)-4);

  with Chart1.Axes.Bottom do
  begin
    PositionPercent:=50;
    SetMinMax(-4,4);
    MaximumOffset:=1;
    MinimumOffset:=1;
  end;

  with Chart1.Axes.Left do
  begin
    PositionPercent:=50;
    SetMinMax(-4,4);
    MaximumOffset:=1;
    MinimumOffset:=1;
  end;

  ReDrawAxisLabels;
end;

procedure TForm1.ReDrawAxisLabels;
var tmpIncrement, tmpValue: Double;
begin
  with Chart1.Axes.Left do
  begin
    tmpIncrement:=(Maximum-Minimum)/10;
    Items.Clear;
    tmpValue:=Minimum;
    while tmpValue <= Maximum do
    begin
      Items.Add(tmpValue);
      tmpValue:=tmpValue+tmpIncrement;
    end;
  end;

  with Chart1.Axes.Bottom do
  begin
    tmpIncrement:=(Maximum-Minimum)/10;
    Items.Clear;
    tmpValue:=Minimum;
    while tmpValue <= Maximum do
    begin
      Items.Add(tmpValue);
      tmpValue:=tmpValue+tmpIncrement;
    end;
  end;
end;

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  ReDrawAxisLabels;
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  ReDrawAxisLabels;
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

PoLabs
Newbie
Newbie
Posts: 28
Joined: Wed Jun 06, 2007 12:00 am

Re: Fixed grid

Post by PoLabs » Tue Dec 29, 2009 5:00 pm

Yes that is right solution for me. You guys really rock! Thank you for your help again. :!:

:wink:

Best regards,
PoLabs

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

Re: Fixed grid

Post by Yeray » Wed Dec 30, 2009 8:15 am

Hi PoLabs,

Thanks to you for your kindness!
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

Post Reply