Once again: I want to avoid labels overlapping on bottom axis and ensure two adjacent labels have a free space between them. So labels are thinned to maximum 20 labels simultaneously visible.
As I can see from my experiments:
In
BeforeDraw event FirstVisibleIndex/LastVisibleIndex have
incorrect values (FirstVisibleIndex=0 and LastVisibleIndex=line1.Count after the first zoom; after the second zoom FirstVisibleIndex and LastVisibleIndex have values of the first zoom and so on) but I
can manipulate labels.
In
AfterDraw event FirstVisibleIndex/LastVisibleIndex have
correct values but I
cannot manipulate labels (clear/add has no effect).
So the only workaround that I see is the following (force redraw after initial draw + drawing custom labels on redraw):
Code: Select all
private Boolean FirstAndLastVisibleIndexesAreCorrect = true;
private void TChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
if (!FirstAndLastVisibleIndexesAreCorrect)
tChart1.Refresh();
}
private void TChart1_BeforeDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
FirstAndLastVisibleIndexesAreCorrect = !FirstAndLastVisibleIndexesAreCorrect;
if (FirstAndLastVisibleIndexesAreCorrect)
DrawLabels(maxDisplayedLabelsForBottomaAxis);
}
That workaround archeives the goal but it's very bad (hits performance and maybe have some other side effects).
Moreover labels are not fully visible - chart isn't recalculating vertical space that is needed to draw bottom axis labels for some reason:
The only workaround is to use the following code (draw labels every time):
Code: Select all
private Boolean FirstAndLastVisibleIndexesAreCorrect = true;
private void TChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
if (!FirstAndLastVisibleIndexesAreCorrect)
tChart1.Refresh();
}
private void TChart1_BeforeDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
{
FirstAndLastVisibleIndexesAreCorrect = !FirstAndLastVisibleIndexesAreCorrect;
DrawLabels(maxDisplayedLabelsForBottomaAxis);
}
But it hits performance even worse because my custom labels are drawn on initial draw and on force redraw.
I've uploaded sample app
here
BTW: long time ago in
TeeChart V2 I was successfully using
Zoomed/
UndoneZoom/
Scroll events to obtain FirstVisibleIndex/LastVisibleIndexand draw my custom labels. Now in
TeeChart V4 inside that events FirstVisibleIndex/LastVisibleIndex have incorrect values.
To sum up: to draw custom labels depending on first and last visible points it is vital to have an event with correct FirstVisibleIndex/LastVisibleIndex
and which allows to manipulate labels. Some time ago it was
Zoomed/
UndoneZoom/
Scroll, but now it's not working. Maybe you can repair them?
P. S. If there is enother way to ensure two adjacent labels have a free space between them (e. g. tChart1.Axes.Bottom.Labels.Space = 10) - any help will be appreciated..