Page 1 of 1

Fixed grid

Posted: Thu Dec 24, 2009 12:31 pm
by 9245460
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. ;)

Re: Fixed grid

Posted: Thu Dec 24, 2009 2:18 pm
by narcis
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.

Re: Fixed grid

Posted: Mon Dec 28, 2009 8:35 am
by 9245460
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

Re: Fixed grid

Posted: Mon Dec 28, 2009 12:08 pm
by yeray
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;

Re: Fixed grid

Posted: Tue Dec 29, 2009 11:01 am
by 9245460
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.


Re: Fixed grid

Posted: Tue Dec 29, 2009 4:47 pm
by yeray
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;

Re: Fixed grid

Posted: Tue Dec 29, 2009 5:00 pm
by 9245460
Yes that is right solution for me. You guys really rock! Thank you for your help again. :!:

:wink:

Best regards,
PoLabs

Re: Fixed grid

Posted: Wed Dec 30, 2009 8:15 am
by yeray
Hi PoLabs,

Thanks to you for your kindness!