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 |