I have function "PlaceChartObjects" that automatically calculate the position of custom axis, legend and resize chart margins to prepare place for this elements.
The problem is that I have to call this function and pTChart->Draw() a few times to get proper results because some objects size have wrong width or height after first pass.
This is very inefficient because it is called from ChartAfterDraw event to reflect changes from Chart Editor immediately.
Code: Select all
void __fastcall CBasicChartManager::ChartAfterDraw(TObject *Sender)
{
if(pTChart)
{
ResetAxisPositions();
ChartTools->PrepareAxisVisibility(pTChart);
CheckToolsVisibility();
ChartTools->PlaceChartObjects(pTChart, this);
TNotifyEvent OnAfterDraw = pTChart->OnAfterDraw;
try
{
pTChart->OnAfterDraw = NULL;
pTChart->Draw();
ChartTools->PlaceChartObjects(pTChart, this);
SetAxisGridVisibility();
pTChart->Draw();
}
__finally
{
pTChart->OnAfterDraw = OnAfterDraw;
}
}
}
Best Regards,
Grzegorz