I am trying to set the subtitle of my chart to the time/date representation of the span of the X-axis. (eg. 1 Jan 2003 - 30 May 2004).
I am doing this in the 'OnBeforeDrawAxis' event at which time I can access 'Chart->BottomAxis->Minimum' & 'Chart->BottomAxis->Maximum'.
At this stage I set the text of the subtitle by using -
Chart->SubTitle->Text->Text = TDateTime(startTime).DateString() + " to " + TDateTime(endTime).DateString();
Unfortunately, the subtitle does not update with this modified text until the "next" time the chart is re-drawn. If I attempt to capture the bottom axis minimum and maximum values earlier then I may not get the right range (assuming I want to capture the zoomed axis range as well).
Does anyone have any comments about this ?
David.
Sequence of events
Hi David,
have you tried to add :
Chart1.Draw();
after the Data is added to the Chart ?
Josep Lluis Jorge
http://support.steema.com
have you tried to add :
Chart1.Draw();
after the Data is added to the Chart ?
Josep Lluis Jorge
http://support.steema.com
re: Sequence of events (sub title)
Josep,
Executing a Chart.Draw() DOES appear to work but of course causes the chart to be drawn twice which is not the most desirable thing to do. Also, the calling of Draw() needs to be done carefully to ensure that the graph drawing does not end up in an infinite loop.
Bearing in mind that the subtitle content is based on information on the graph and I want the subtitle to be updated automatically with this; is there a better way of solving the problem ?
Regards, David Peacock.
Executing a Chart.Draw() DOES appear to work but of course causes the chart to be drawn twice which is not the most desirable thing to do. Also, the calling of Draw() needs to be done carefully to ensure that the graph drawing does not end up in an infinite loop.
Bearing in mind that the subtitle content is based on information on the graph and I want the subtitle to be updated automatically with this; is there a better way of solving the problem ?
Regards, David Peacock.
A workaround could be to manually draw required text in TChart.OnAfterDraw event using the Canvas.TextOut method.
This way there will be no need to call the Draw method.
Josep Lluis Jorge
http://support.steema.com
This way there will be no need to call the Draw method.
Code: Select all
void __fastcall TForm1::Chart1AfterDraw(TObject *Sender)
{
startTime = Chart1->Axes->Bottom->Minimum;
endTime = Chart1->Axes->Bottom->Maximum;
Chart1->Canvas->TextOut(10,10,TDateTime(startTime).DateString() + " to " + TDateTime(endTime).DateString());
}
Josep Lluis Jorge
http://support.steema.com