2019-02-19 C++ Builder XE4 > TeeChart > geometry > to fix the left position of the graph drawing region >[whatever the label significant figures are] + [dataset assigned to left- or right-axes]  

```txt:Environment
C++ Builder XE4
```

This article is a translation version of [the Japanese article](https://qiita.com/7of9/items/c84d541d95d5106c7f71) so that English speaking people can understand what I implemented.

### About

- The left position of the TChart's graph drawing region varies according to the followings:
    - A. different siginificant figures of the left axis
        - e.g.: 8.0
        - e.g.: 8.50
    - B. left- or right- axes setting for the dataset
- goal: to set left axis to the same position whatever the condition is 

### implementation

```Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <VCLTee.Chart.hpp>
#include <VCLTee.Series.hpp>
#include <VCLTee.TeEngine.hpp>
#include <VCLTee.TeeProcs.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// Component managed by IDE
	TChart *Chart1;
	TFastLineSeries *Series1;
	TMemo *Memo1;
	TButton *B_upper;
	TButton *B_middle;
	TButton *B_leftRight;
	TShape *Shape1;
	TShape *Shape2;
	void __fastcall B_upperClick(TObject *Sender);
	void __fastcall B_middleClick(TObject *Sender);
	void __fastcall B_leftRightClick(TObject *Sender);
	void __fastcall Chart1AfterDraw(TObject *Sender);
private:	// User declaration
	void __fastcall updateGraphView(TChart *chrPtr);
	void __fastcall addDummyData();
	void __fastcall changeChartRect(int left, int top, int right, int bottom);
	void __fastcall correctForLabelTextWidth(int atop);
public:		// User declaration
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
```

```Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include <DateUtils.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------

static const int kLeft_chartRect = 100; // This value is used as a left-side-reference

__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
	addDummyData();
	Shape1->Left = kLeft_chartRect;
}
//---------------------------------------------------------------------------
// { generic function
void __fastcall TForm1::updateGraphView(TChart *chrPtr)
{
	if (chrPtr == NULL) {
		return;
	}

	// to update the graph draw
	int pre = chrPtr->Title->Font->Size;
	chrPtr->Title->Font->Size = pre + 1;
	chrPtr->Title->Font->Size = pre;

	//
	Application->ProcessMessages();  // ***necessary to obtain correct [ChartRect.Top]
	Sleep(100); // msec
}
// } generic function
//---------------------------------------------------------------------------
void __fastcall TForm1::addDummyData()
{
	Chart1->Series[0]->XValues->DateTime = true;
	Chart1->BottomAxis->DateTimeFormat = L"nn:ss";

	TDateTime dt = Now();

	for (int idx=0; idx < 10; idx++) {
		double yval = (1+ idx) % 2;
		Series1->AddXY(dt, yval, "", clRed);
		dt = IncSecond(dt, 1);
	}
}

void __fastcall TForm1::changeChartRect(int left, int top, int right, int bottom)
{
	Chart1->CustomChartRect = true;
	Chart1->ChartRect = Rect(left, top, right, bottom);
	updateGraphView(Chart1);   // ***necessary to obtain correct [ChartRect.Top]
}

void __fastcall TForm1::correctForLabelTextWidth(int atop)
{
	int diff_hori = Chart1->ChartRect.Left - kLeft_chartRect;
	changeChartRect(kLeft_chartRect- diff_hori, atop, 500, 300);

	// for debug
	String infmsg = String().sprintf(L"diff: %d", diff_hori);
	Memo1->Lines->Add(infmsg);
}

void __fastcall TForm1::B_upperClick(TObject *Sender)
{
	int atop = 0;  // set graph to the upper
	changeChartRect(kLeft_chartRect, atop, 500, 300);
	correctForLabelTextWidth(atop);
}

void __fastcall TForm1::B_middleClick(TObject *Sender)
{
	int atop = 100;  // set graph to the center
	changeChartRect(kLeft_chartRect, atop, 500, 300);
	correctForLabelTextWidth(atop);
}

void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
	Shape2->Left = Chart1->ChartRect.Left;  // for the position reference
}
//---------------------------------------------------------------------------

void __fastcall TForm1::B_leftRightClick(TObject *Sender)
{
	// switch between left and right axes

	if (B_leftRight->Tag == 0) {
		B_leftRight->Tag = 1;
		Chart1->Series[0]->VertAxis = aRightAxis;
	} else {
		B_leftRight->Tag = 0;
		Chart1->Series[0]->VertAxis = aLeftAxis;
	}
}
//---------------------------------------------------------------------------
```

### Buttons

- [1] B_upper: to set graph to the upper 
- [2] B_lower: to set graph to the center
- [3] B_leftRight: switch between left- or right- axes


### Example

After clicking [1],
(Green square: located at the same position always as a reference)
![2019-02-19_17h37_15.png](https://qiita-image-store.s3.amazonaws.com/0/32870/803c0652-1657-342c-e36d-600ed6c68eba.png)

After clicking [2],
![2019-02-19_17h37_28.png](https://qiita-image-store.s3.amazonaws.com/0/32870/f7370ee3-d9d8-a13e-4206-2fe34e2f58cf.png)

Clicking [3] ,then clicking [1]
![2019-02-19_17h37_35.png](https://qiita-image-store.s3.amazonaws.com/0/32870/ce224d25-9e00-bc0e-dd66-51349773cdb6.png)

Then clicking [2]
![2019-02-19_17h37_39.png](https://qiita-image-store.s3.amazonaws.com/0/32870/61bf9e01-6b4d-2e12-682e-02c1fdee022b.png)

Under all the conditions, the graph's left axis is located at the same position.


### StackOverflow

- [C++ Builder and TeeChart > how to fix the graph range even when the axis is set to left or right side](https://stackoverflow.com/questions/54729397/c-builder-and-teechart-how-to-fix-the-graph-range-even-when-the-axis-is-set)