ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Detect Truncate
Posted by Rick on May-22-2014 06:56
In my PHP XYChart legend box, I sometimes truncate the entries within my legend. This is
sometimes due to a few series with long names or to having too many series to fit the
height of the graph.

Is there a way to detect that I'm going to truncate a TextBox or LegendBox so that I could
then play some games (such as reducing the font size) to make it fit prior to creating the
chart?

Thanks!

  Re: Detect Truncate
Posted by Peter Kwan on May-24-2014 01:41
Hi Rick,

Sorry for the late reply.

You may consider to measure the length of the legend text to see if it is "too long". They
can be measured like:

#assume this is all the entries in your legend box
$allLegendText = array($nameOfDataSet0, $nameOfDataSet1, $nameOfDataSet2, ....);

#create a dummy text box for the purpose of measuring text length
$measurer = $c->addText(-9999, -9999, "", "arial.ttf", 10);

#loop through all the legend text to get the maximum length
$maxTextLength = 0;
for ($i = 0; $i < count($allLegendText); ++$i) {
   $measurer->setText($allLegendText[$i]);
   $maxTextLength = max($maxTextLength, $measurer->getWidth());
}


Note that what is "too long" depends on your chart configuration, such as the maximum
legend box width (if configured with setMaxWidth), the distance between the left border
of the legend box to the right border of the chart, the legend icon size (configurable with
setKeySize and can also depends on the symbol size you use when you add line or
scatter layers), etc.. You would need to estimate a suitable length and adjust your font
if the text exceeds that length.

Regards
Peter Kwan