How to add a series without changing the Axis scale?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
BE
Newbie
Newbie
Posts: 41
Joined: Tue Nov 16, 2004 5:00 am

How to add a series without changing the Axis scale?

Post by BE » Wed Sep 05, 2007 2:20 pm

Hi,

I have a TFastLineSeries in a TChart. The BottomAxis is set to Automatic. I wanted to add a TGanttSeries to the chart without modifying the scale of the bottom axis even it is set to Automatic. Is there a way of doing this? At the moment, every time I add a Ganttseries, the BottomAxis changes because the BottomAxis is set to Automatic.

Thanks

-Bill

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

Post by Narcís » Wed Sep 05, 2007 2:43 pm

Hi Bill,

This is most likely because TFastLineSeries use values from double x values while TGanttSeries' x values are TDateTime, which actually are doubles as well but start at higher values. That may be the reason why your bottom axis scale is increased. To avoid this, if, for example your TFastLineSeries has 25 x values (from 0 to 24) you should also add TGanttSeries values in this x range, a practical example:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  for i:=0 to 25 do
    Series1.AddXY(i,i);
end;

procedure TForm1.Button1Click(Sender: TObject);
var tmpGantt: TGanttSeries;
    i: Integer;
begin
  tmpGantt:=TGanttSeries.Create(self);
  Chart1.AddSeries(tmpGantt);

  tmpGantt.AddGantt(0,5, 0, '');
  tmpGantt.AddGantt(3,8, 5, '');
  tmpGantt.AddGantt(7,15, 10, '');
end;
For more information on how TDateTime values work please read TDateTime entry in Delphi's help or read it here.
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

BE
Newbie
Newbie
Posts: 41
Joined: Tue Nov 16, 2004 5:00 am

Post by BE » Wed Sep 05, 2007 3:27 pm

Thanks for the fast reply. My question is actually a general one. Is there a way to remove a series from Axis.Automatic action. My GanttSeries is out side the range of the Chart and FastLineSeries, however, I don't want the chart to change scale to reflect that. I only wanted the automatic feature to be applied to FastLine. For example, each series has a ShowInLegend option. Is there an option for a series NOT to be included in Axis.Automatic calculation?

Thanks

-Bill

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

Post by Narcís » Thu Sep 06, 2007 8:09 am

Hi Bill,

Ok, you can achieve what you request associating the gantt series to a horizontal custom axis, instead of the default bottom axis, and making it not visible. For more information on how to use axes please read Tutorial 4 - Axis Control.

Thanks in advance.
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

BE
Newbie
Newbie
Posts: 41
Joined: Tue Nov 16, 2004 5:00 am

Post by BE » Thu Sep 06, 2007 7:01 pm

Thanks for the advice. I've tried it and found a "bug"? with MasterAxis.

Please see the following code

------------------------------------

Chart1->LeftAxis->Automatic = 1;


pAxis = new TChartAxis(Chart1);
pAxis->Horizontal = 1;
pAxis->Automatic = 0;
pAxis->Visible = 0;

Series2->CustomHorizAxis = pAxis;

Series2->AddXY(-10, -10, "", clRed);
Series2->AddXY(0, -10, "", clRed);
Series2->AddXY(0, -20, "", clRed);
Series2->AddXY(20, -20, "", clRed);


for(int i = 0; i < 101; i++)
{
Series1->AddXY(i, - i * i / 100.0, "", clRed);
}

pAxis->MasterAxis = Chart1->BottomAxis;

---------------------------------

When I move the chart by right mouse dragging, if I move vertically, Series2 would not show up, Series2 will show if I drag horizontally.

Am I doing something wrong?

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

Post by Narcís » Fri Sep 07, 2007 7:43 am

Hi BE,

First of all please notice that you should populate Gantt series using AddGantt(StartDate, EndDate, YValue). Also please notice that, as said in the documentation, MasterAxis is an internal property:

property MasterAxis: TChartAxis;

Unit
TeEngine

Description
Internal property. The current behaviour might change in future versions.

When an axis has the MasterAxis property set to another axis, when the other axis changes its minimum or maximum values (due to zoom or scroll), our axis gets the same minimum and maximum values.

MasterAxis property can be used to synchronize axes scales automatically without having to do this by code:

Old:

Code: Select all

Chart1.CustomAxes[3].SetMinMax(  Chart1.Axes.Left.Minimum, Chart1.Axes.Left.Maximum );
New:

Code: Select all

Chart1.CustomAxes[3].MasterAxis := Chart1.Axes.Left;
Having said that, this works fine for me here using TeeChart Pro v8. Which TeeChart version are you using? The behaviour you describe happens when MasterAxis is not being used. You could also try this:

Code: Select all

	Chart1->CustomAxes->Items[0]->MasterAxis = Chart1->Axes->Bottom;
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

BE
Newbie
Newbie
Posts: 41
Joined: Tue Nov 16, 2004 5:00 am

Post by BE » Fri Sep 07, 2007 3:02 pm

Ok, I think I know where my problem is now. It is a general question.

When I do the following;

Chart1->BottomAxis->Automatic = 1;

for(int i = 0; i < 101; i++)
Series1->AddXY(i, i, "", clRed);

Chart1 Bottom Axis Mininmum is not 0.0 and Max is not 100.0. It is something else. Min is a bit less then 0.0 and Max is a bit more then 100.0.

If I set Series2->CustomAxis to something other than Chart1->BottomAxis and set teh customAxis to MinMax(0, 100), then, Series1 and Seri2 Axes are a bit mis aligned.

__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Chart1->LeftAxis->Automatic = 1;
Chart1->BottomAxis->Automatic = 1;

for(int i = 0; i < 101; i++)
Series1->AddXY(i, i, "", clRed);

pAxis = new TChartAxis(Chart1);
pAxis->Horizontal = 1;
pAxis->Automatic = 0;
pAxis->Visible = 0;

pAxis->SetMinMax(Chart1->BottomAxis->Minimum, Chart1->BottomAxis->Maximum);

However, at this point Chart1->BottomAxes are 0.0. How do I get the Ases info at this point so I can aligned the two axes?

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

Post by Narcís » Fri Sep 07, 2007 3:10 pm

Hi BE,

This is most likely because the chart hasn't been drawn yet and therefore axes don't have their values calculated yet. You could do something like this:

Code: Select all

	Chart1->Draw();
	pAxis ->SetMinMax(Chart1->Axes->Bottom->Minimum, Chart1->Axes->Bottom->Maximum);
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

BE
Newbie
Newbie
Posts: 41
Joined: Tue Nov 16, 2004 5:00 am

Post by BE » Fri Sep 07, 2007 3:25 pm

What a super fast reply. Thanks!!!!! I'll try that

BE
Newbie
Newbie
Posts: 41
Joined: Tue Nov 16, 2004 5:00 am

Post by BE » Fri Sep 07, 2007 3:41 pm

Tried it. Now when I use debuger, the Chart1->BottomAxis Min and Max are 0.0 and 100.0, but the Axes are still mis aligned for some reason. When I make both Axes visible, it is clear that they are mis aligned. However, when I scroll the chart, they are aligned right a way! There's a diff between what's displayed and what Chart1->Bottomaxis->Min and Mas are! Why is that. What do I have to do to get them aligned at the Chart creation point?

I'm using TeeChart 7.02

Thanks

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

Post by Narcís » Fri Sep 07, 2007 3:48 pm

Hi BE,

Won't you have Chart1->Axes->Bottom->MinimumOffset or Chart1->Axes->Bottom->MaximumOffset different from zero either set at design-time or at run-time? You can try adding this:

Code: Select all

	Chart1->Axes->Bottom->MinimumOffset=0;
	Chart1->Axes->Bottom->MaximumOffset=0;
Also notice that there are much newer versions of TeeChart Pro v7 VCL available at the client download area.

If the problem persists please 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.

Thanks in advance.
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

BE
Newbie
Newbie
Posts: 41
Joined: Tue Nov 16, 2004 5:00 am

Post by BE » Fri Sep 07, 2007 3:53 pm

Thanks. I'll try that.

I think the problem is just my understanding, rather then your problem. I do have version 7.11 for BCB 2007, but the project I'm working on is BCB 6. I will soon (hope) to get V8.

BE
Newbie
Newbie
Posts: 41
Joined: Tue Nov 16, 2004 5:00 am

Post by BE » Fri Sep 07, 2007 4:03 pm

tried that as well. Got the same result.

If I do the following;

Chart1->Draw();

Chart1->BottomAxis->SetMinMax(Chart1->BottomAxis->Minimum, Chart1->BottomAxis->Maximum);

pAxis->SetMinMax(Chart1->BottomAxis->Minimum, Chart1->BottomAxis->Maximum);

That gets the Axes aligned.

I will create a sample project and send it to you.

Thanks

BE
Newbie
Newbie
Posts: 41
Joined: Tue Nov 16, 2004 5:00 am

Post by BE » Fri Sep 07, 2007 4:51 pm

Ok. Just sent the smple project in the zipped format call Problem Case

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

Post by Narcís » Mon Sep 10, 2007 9:24 am

Hi BE,

Thanks for the example project. In that case, it works fine synchronizing bottom and custom axes in OnZoom, OnScroll and OnUndoZoom events as shown below. Please also notice that BottomAxis like nomenclature is deprecated and you should better use Axes->Bottom.

Code: Select all

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    Chart1->BottomAxis->Automatic = 1;

    Chart1->LeftAxis->Increment = 100 / 5;
    Chart1->BottomAxis->Increment = 100 / 5;

    for(int i = 0; i < 101; i++)
        Series1->AddXY(i, -i*i /100.0, "", clRed);

    Chart1->BottomAxis->MinimumOffset = 0;
    Chart1->BottomAxis->MaximumOffset = 0;
    Chart1->Draw();

    TChartAxis * pAxis = new TChartAxis(Chart1);
    pAxis->Horizontal = 1;
    pAxis->Automatic = 0;
    pAxis->Visible = 1;

    Series2->CustomHorizAxis = pAxis;

    Series2->AddXY(0, -20, "", clRed);
    Series2->AddXY(20, -20, "", clRed);
    Series2->AddXY(20, -40, "", clRed);

//    Chart1->BottomAxis->SetMinMax(Chart1->BottomAxis->Minimum, Chart1->BottomAxis->Maximum);
    //pAxis->SetMinMax(Chart1->BottomAxis->Minimum, Chart1->BottomAxis->Maximum);
    SynchronizeAxes();
}
//---------------------------------------------------------------------------

void TForm1::SynchronizeAxes()
{
    Chart1->CustomAxes->Items[0]->SetMinMax(Chart1->Axes->Bottom->Minimum, Chart1->Axes->Bottom->Maximum);
}

void __fastcall TForm1::Chart1Zoom(TObject *Sender)
{
    SynchronizeAxes();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Chart1UndoZoom(TObject *Sender)
{
    SynchronizeAxes();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Chart1Scroll(TObject *Sender)
{
    SynchronizeAxes();
}
//---------------------------------------------------------------------------
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

Post Reply