Page 1 of 1

Y axis scaled per series

Posted: Fri Mar 13, 2015 7:39 pm
by 9238362
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;

Re: Y axis scaled per series

Posted: Mon Mar 16, 2015 10:10 am
by yeray
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;
  }
}