|
Scrolling Chart - AddMark label is scrolling outside plot area |
Posted by knewby on May-28-2011 01:25 |
|
Hi Peter -
I have a quick question that I'm sure you can help with. I was able to make my chart scrollable thanks to your previous help and the awesome examples. I have added a vertical brown line (addMark) to my chart (when a product id changes). The vertical mark lines scroll normally (every 30 seconds), but when each vertical mark line reaches the left y axis, the labels scroll off the plot area. The mark lines behave normally and do not scroll off the plot area. Is there somethng I can do to prevent the labels from displaying outside the plot area?
if ($CoilNumber[$i] <> $CoilNumber[$i+1]) {
# Add a vertical brown (0x995500) mark line at x = $i
# when coil number changes
$xMark1 = $c->xAxis->addMark($i, 0x995500, $CoilNumber[$i]);
# Set the mark line width to 2 pixels
$xMark1->setLineWidth(2);
# Put the mark label at the top left of the mark line
$xMark1->setAlignment(TopLeft);
# Rotate the mark label by 90 degrees so it draws vertically
$xMark1->setFontAngle(90);
}
Thanks in advance again for your patience and advice!
knewby
|
Re: Scrolling Chart - AddMark label is scrolling outside plot area |
Posted by Peter Kwan on May-28-2011 02:01 |
|
Hi knewby,
You may consider the following method:
(a) Set a semi-transparent background color for the label. This will not avoid the label from scrolling outside the plot area, but this will make the label easily readable even if it overlaps with the axis.
$xMark1->setBackground(0x80ffffff);
(b) Do not add the text label if the vertical line is too close to the left edge. For example (in PHP 5):
#add the label only if there is at least 20 pixels left
if (($i - $minX) * $c->getPlotArea()->getWidth() / ($maxX - $minX) >= 20)
$xMark1 = $c->xAxis->addMark($i, 0x995500, $CoilNumber[$i]);
else
$xMark1 = $c->xAxis->addMark($i, 0x995500);
(c) Alternative, you may position the label differently (such as using TopRight) if the line is too close to the left y-axis.
Hope this can help.
Regards
Peter Kwan |
Re: Scrolling Chart - AddMark label is scrolling outside plot area |
Posted by knewby on May-28-2011 05:15 |
|
I chose option (b). And it works perfectly. (Huge light bulb effect with your answer by the way.) This is a really cool product. And you're a ChartMeister. Thanks again Peter!!! |
|