Scrolling one date at a time

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Dave C.
Newbie
Newbie
Posts: 7
Joined: Fri Jan 30, 2009 12:00 am
Location: Canada

Scrolling one date at a time

Post by Dave C. » Wed Feb 04, 2009 3:55 pm

Hello,

I am new to TChart so this may be a simple question to answer. I have a bar graph with dates along the x axis and a TChartScrollBar. When I scroll the graph using the arrows on the scroll bar the graph moves one page at a time. I would like to move just one date (data point) at a time. How can I do this?

Thanks,

Dave.

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

Post by Yeray » Wed Feb 04, 2009 4:15 pm

Hi Dave,

Here there is an example doing it, I hope will help:

Code: Select all

const PointsPerPage = 10;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  with Chart1.Axes.Bottom do
  begin
    Automatic := False;
    Minimum := 0;
    Maximum := PointsPerPage - 1;
  end;

  Chart1[0].FillSampleValues(50);

  Series1.XValues.DateTime := true;

  ScrollBar1.Max := Chart1[0].Count - PointsPerPage;
end;

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
  with Chart1.Axes.Bottom do
  begin
    Minimum := ScrollBar1.Position;
    Maximum := ScrollBar1.Position + PointsPerPage - 1;
  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

Dave C.
Newbie
Newbie
Posts: 7
Joined: Fri Jan 30, 2009 12:00 am
Location: Canada

Post by Dave C. » Wed Feb 04, 2009 6:52 pm

Thank you for the quick response. That was what I was looking for.

I noticed that when you turn off “Automatic”, bars that are added using Series1.Add (x,’’,clr) are not in proportion and the more bars you add the wider each bar gets. Is there another setting such as Automatic that will keep the correct proportion of the bars? That is, the bars do not automatically become wider with each add?

Thanks again,

Dave.

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

Post by Yeray » Thu Feb 05, 2009 8:48 am

Hi Dave,

I'm not sure to understand you. I've added a button with the following code to the example above and it seems to work fine here.

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  Chart1[0].Add(random*Chart1[0].MaxYValue,'',clTeeColor);
  ScrollBar1.Max := ScrollBar1.Max + 1;
end;
If you still have problems with this, please, could you send us a simple example project we can run "as-is" to reproduce the problem here?
You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
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

Dave C.
Newbie
Newbie
Posts: 7
Joined: Fri Jan 30, 2009 12:00 am
Location: Canada

Post by Dave C. » Thu Feb 05, 2009 2:29 pm

Yeray,

Thanks for your help. I am sure it is something I am missing in a property somewhere.

If Chart1.Axes.Bottom.Automatic is true, then the bars draw correctly side by side. If I set Automatic to false so that I can scroll, the bars are incorrect – they overlap and stack onto one another. I have removed the scroll bar from the example below to simplify it.

I have added two series to the chart; both are Standard bar, 3D and smooth. No other changes are made through the Edit Chart settings.

Code: Select all

procedure TfrmChartExample.FormShow(Sender: TObject);
begin
  Chart1.MaxPointsPerPage:=10;

  with Chart1.Axes.Bottom do
  begin
    Automatic := true;  //If true, bars draw correctly.
                        //If false, bars are incorrect.
    Maximum := Date + Chart1.MaxPointsPerPage-1;
    Minimum := Date;
  end;

  Series1.XValues.DateTime := true;
  Series2.XValues.DateTime := true;
end;

procedure TfrmChartExample.Button1Click(Sender: TObject);
var
  i :integer;
  x :double;
  y :double;
begin
  for i := 0 to 50 do
  begin
    x:= IncDay(Date, i);
    y:= i+1;
    if y>10 then y:=8;
    series1.AddXY(x, y, '', clBlue);
    series2.AddXY(x, y-1, '', clSkyBlue);
  end;
end;
I am sure it is a simple setting I am missing, but I don’t know where to look. If you would like me to zip up the project and send it to you let me know.

I am using Delphi 2006, win 32.

Thanks,

Dave.

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

Post by Yeray » Thu Feb 05, 2009 3:49 pm

Hi Dave,

Yes it would be better if you send us this example and, if possible, with a picture showing your result and maybe another showing the result you expected.

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.
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

Dave C.
Newbie
Newbie
Posts: 7
Joined: Fri Jan 30, 2009 12:00 am
Location: Canada

Post by Dave C. » Thu Feb 05, 2009 4:05 pm

Hi Yeray,

I have posted ChartExample.zip to your Upload Page. I included two BMPs of the graph when Automatic is set to true (correct graph) and when Automatic is set to false (incorrect graph).

Thanks,
Dave.

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

Post by Yeray » Fri Feb 06, 2009 4:55 pm

Hi Dave,

The Chart property MaxPointsPerPage is used when one wants to use the Chart pagination feature. On the other hand, you are scrolling your chart with a scrollbar. That's why setting this property your chart is confusing.

The following code works now for us here:

Code: Select all

procedure TfrmChartExample.FormShow(Sender: TObject);
var MaxPointsPerPage: Integer;
begin
  MaxPointsPerPage:=10;

  with Chart1.Axes.Bottom do
  begin
    Automatic := false; 
    Maximum := Date + MaxPointsPerPage-1;
    Minimum := Date;
  end;

  Series1.XValues.DateTime := true;
  Series2.XValues.DateTime := true;
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

Dave C.
Newbie
Newbie
Posts: 7
Joined: Fri Jan 30, 2009 12:00 am
Location: Canada

Post by Dave C. » Mon Feb 09, 2009 7:00 pm

Yeray,

Thanks! I have corrected the problem with the MaxPointsPerPage and the bars are now drawing correctly.

I gave up trying to use TChartScrollBar as I couldn’t get it to work with the dates. Using your ideas above, I added a regular scrollbar and added:

Code: Select all

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
  with Graph.Axes.Bottom do
  begin
    SetMinMax(StartDate + ScrollBar1.Position, StartDate + ScrollBar1.Position + PointsPerPage - 1);
  end;
end;
That works just the way I want it to!

Best regards,

Dave.

[/code]

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

Post by Yeray » Tue Feb 10, 2009 8:55 am

Hi Dave,

Yes, we recommend to use the standard ScrollBar instead of TChartScrollBar because it presents some problems.

I'm happy to see it works fine!
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