Page 1 of 1

Displaying labels overlap

Posted: Thu Apr 05, 2007 11:30 am
by 9243578
I have a problem with displaying labels on the top-axis.
I am using the top axis to show 2 times, which are very close to each other, but because there is too much overlap, TeeChart hides the second label and it doesn't shows the vertical line, while those are both crucial lines. The AlternateLabels property won't work either for my problem, is there any way I can still show both labels and their vertical lines, using different Y-positions?

Kind regards,
Thomas

Posted: Thu Apr 05, 2007 1:45 pm
by narcis
Hi Thomas,

You could try using the other suggestions made here.

Thanks in advance.

Posted: Wed Apr 11, 2007 6:45 am
by 9243578
Thank you.

A combination of the LabelsAlternate (true) and LabelsSeperation (0) solved the problem very well!

Posted: Wed Apr 11, 2007 1:32 pm
by 9243578
I thought my problems were solved with overlapping labels, but I just ran into a new problem. :(

Image

(Note the top axis, in which the times to the right are gracefully alternated!)

The 2 times (marked with a red circle), should always be shown and are placed in a seperate Series:

Code: Select all

TChartSeries *serBottomText;
The times in between are put in another series (TLineSeries), but the problem is that it always first draws the serBottomText, and then it draws the other series, and then it doesn't matters if there is any overlap (I think it has something to do with the draw orders of the labels, because they are in different series).

Is there a way I can fix this, so that no overlap takes place (here it happens on the right side, but there are also cases where it happens on the left side). Setting LabelsSeperation to 0 and LabelsAlternate to true is also no option, because there can be over 200 times on the x-axis so it's already hiding most of the x-values.

Posted: Wed Apr 11, 2007 2:08 pm
by narcis
Hi TMuijsert,

Could you please send us a little bit more information about your application and specifically how are those labels created? Do you use overlapped axes? Do you use custom labels?

Thanks in advance.

Posted: Thu Apr 12, 2007 6:32 am
by 9243578
Thanks for the fast reply, I will post some relevant code in the order it's being executed and I hope it can tell enough about the problem:

Notes:
- iTimeScale is an integer used to scale times, I still have to try out the EncodeTime method
- The x-value will always be between 0 and iTimeScale, so it can never cross the left or right border
- I omitted the y-value, because it comes from a big data structure
- strAnsiTime are all the times between the first and the last time, the times that are causing the overlap!

Code: Select all

/* Header */
TChart *chData;
TChartSeries *serBottomText;
String *strStartTime;
String *strTerminateTime;
/* End Header */

/* Construction */
serBottomText = new TChartSeries(chData);
serBottomText->HorizAxis = aBottomAxis;
serBottomText->ShowInLegend = false;

serBottomText->AddX(0, *strStartTime, clBlack);
serBottomText->AddX(iTimeScale, *strTerminateTime, clBlack);

chData->AddSeries(serBottomText);
/* End Construction */

/* Building the graph (in the case of 1 line) */
TLineSeries *serData = new TLineSeries(Owner);
chData->AddSeries(serData);

// This happens in a double for-loop
serData->AddXY(x-value, y-value, strAnsiTime, clBlack);
/* End Building the graph */
I hope this information clears up enough of the problem :)

Posted: Thu Apr 12, 2007 7:31 am
by narcis
Hi TMuijsert,

It is still not clear to me how labels are added to horizontal axes. By default, TeeChart draws the labels for first series. You said that bottom axis first and last labels where always visible and the rest of the labels vary, is that correct? If so, how many axes do you have in your project and how are labels added to them? Are they added automatically, do you use custom labels?

Thanks in advance.

Posted: Tue Apr 17, 2007 7:17 am
by 9243578
Hi NarcĂ­s,

Sorry for the late reply, but I had to change some things in the code, to make the complication a little easier to understand (and hopefully to solve).

Instead of times, I am now showing times in minutes and I've added all the numbers in 1 serie on the horizontal axis.

However, three problems occur with this:

1) I want to display the realtime below the first and the last time, as multiline labels, but I can't get this to work.

2) I want the labels to show at a constant distance, right now, the amount of labels shown are determined by the width of the labels, but it would be better if there are about 10 points drawn in between the first and the last label.

3) It doesn't always shows the last label anymore, only when there is the space to draw it, LabelsSeperation doesn't work here, because there can be about 200 numbers on the bottom axis, I only want to show a limited number on a constant distance.

Image

Code: Select all

TChartSeries *serBottomText; // Declaration

serBottomText = new TChartSeries(chData); // Initialisation
serBottomText->HorizAxis = aBottomAxis;
serBottomText->ShowInLegend = false;

serBottomText->AddX(0, "", clBlack); // Scaling with a margin
serBottomText->AddX(iMargin, "0", clBlack);
serBottomText->AddX(iMargin + iLast, String(iLast / 60), clBlack);
serBottomText->AddX(iLast + 2 * iMargin, "", clBlack);

// Looping through all the data and adding it to the serie
for (int i = 0; i < iCountMeasurements; ++i)
{
  for (int j = 0; j < iNumPoints; ++j)
  {
    int iTime = data[i][j]; // Time in seconds
    serBottomText->AddXY(iMargin + iTime, 0, String(iTime) / 60), clBlack);
  }
}
the only relevant axis here in the bottom axis, labels are added to them automatically, from the serBottomText serie, no custom labels are used.

Posted: Tue Apr 17, 2007 10:14 am
by narcis
Hi TMuijsert,
1) I want to display the realtime below the first and the last time, as multiline labels, but I can't get this to work.
It works fine for me here adding labels as shown in the code below. Another option would be manually parsing labels in the OnGetAxisLabel event.

Code: Select all

  Series1.Add(2,'First Line'+#13+'SecondLine',clTeecolor);
  Series1.Add(3,'First Line'+TeeLineSeparator+'SecondLine',clTeecolor);
2) I want the labels to show at a constant distance, right now, the amount of labels shown are determined by the width of the labels, but it would be better if there are about 10 points drawn in between the first and the last label.
You could try setting LabelsSeparation, setting axis Increment or using custom labels to achieve that.
3) It doesn't always shows the last label anymore, only when there is the space to draw it, LabelsSeperation doesn't work here, because there can be about 200 numbers on the bottom axis, I only want to show a limited number on a constant distance.
You could try what's shown in the What's new?\Welcome!\New in Axis\First and Last labels example at the features demo.

You'll find the demo at TeeChart's program group.