Y axis scaled per series

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Banjovi
Newbie
Newbie
Posts: 11
Joined: Thu Sep 22, 2005 4:00 am

Y axis scaled per series

Post by Banjovi » Fri Mar 13, 2015 7:39 pm

Using TeeChart Pro 7.07 with BCB6

I need to create a chart showing multiple line series, each with it's own Y-axis and each Y axis scaled to fill the entire chart. For example, Series1 may range from 250 to 1000 while Series2 ranges from 55 to 80. Hopefully, I can click on either of the line series and make only the Y-axis for that series visible.

Code: Select all

         TLineSeries *ser;
         ser = (TLineSeries *) chrt->AddSeries(__classid(TLineSeries));
         ser->Title = String("Series") + String(i);
         ser->Pen->Visible = true;
         ser->Pen->Width = 2;
         ser->LinePen->OwnerCriticalSection = NULL;

         // This is the part I can't get the syntax right for...all the examples seem to be in Pascal
         TChartAxis *v= new TChartAxis(chrt);
         ser->CustomVertAxis = v;

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

Re: Y axis scaled per series

Post by Yeray » Mon Mar 16, 2015 10:10 am

Hello,

Here it is a simple example derived from the code you posted that seems to work fine for me here.
It creates two line series with two custom axes, one of them moved to the right side.
On the series OnClick event, we are hiding all the axes for the not clicked series.
On the chart OnClickBackground we are showing all the axes again.

Code: Select all

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  chrt->View3D = false;

  for (int i = 0; i < 2; i++) {
	TLineSeries *ser;
	ser = (TLineSeries *) chrt->AddSeries(__classid(TLineSeries));
	ser->Title = String("Series") + String(i);
	ser->Pen->Visible = true;
	ser->Pen->Width = 2;
	ser->LinePen->OwnerCriticalSection = NULL;

	TChartAxis *v= new TChartAxis(chrt);
	ser->CustomVertAxis = v;
	v->Axis->Color = ser->Color;

	ser->FillSampleValues(10);
  }

  chrt->CustomAxes->Items[1]->OtherSide = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::chrtClickSeries(TCustomChart *Sender, TChartSeries *Series,
		  int ValueIndex, TMouseButton Button, TShiftState Shift, int X,
		  int Y)
{
  for (int i = 0; i < chrt->SeriesCount(); i++) {
	chrt->CustomAxes->Items[i]->Axis->Visible = (chrt->Series[i] == Series);
	chrt->CustomAxes->Items[i]->Labels = (chrt->Series[i] == Series);
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::chrtClickBackground(TCustomChart *Sender, TMouseButton Button,
		  TShiftState Shift, int X, int Y)
{
  for (int i = 0; i < chrt->CustomAxes->Count; i++) {
	chrt->CustomAxes->Items[i]->Axis->Visible = true;
	chrt->CustomAxes->Items[i]->Labels = true;
  }
}
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