|
Help with aggregate and addExtraField |
Posted by Warren on Dec-03-2011 02:53 |
|
I need some help with Chartdirector (in PHP)
I am drawing a simple line chart and I am using the extra field to draw a tooltip on the
chart - as a kind of overlay or mask. This works perfectly, however we have run into a
small problem - users are able to draw charts selecting a huge range of data. To
prevent overload on the browser I am using MathArray aggregate to reduce the data,
but this messes up the overlay.
In numbers:
I have a series like this:
$data = array(10,20,30,40,50,60,70,80,90,100 .... 1000);
$timestamps = array(time1, time2 .... time100);
$overlay = array("at 10 status is blue", "at 20 status is blue" ... etc)
data is drawn with $layer0 = $c->addLineLayer($data);
timestamps are drawn with $layer0->setXData($timestamps);
overlay is drawn with $layer0->addExtraField($overlay);
Up to this point everything is perfect, on the normal view count($data) ==
count($overlay), so the mouseover points match up.
But when I aggregate $data and $timestamps to, say, 100 points like this:
$m = new ArrayMath($labels);
$m->selectRegularSpacing(count($timestamps) / 100);
$timestamps = $m->aggregate($timestamps, AggregateFirst);
$data = $m->aggregate($data, AggregateFirst);
my overlay is getting broken (I obviously can't aggregate my overlay)
Does anyone have a way I can fix up $overlay so that it gets drawn correctly (aside
from the obvious and very painful manual manipulation).
Thanks! |
Re: Help with aggregate and addExtraField |
Posted by Warren on Dec-03-2011 02:55 |
|
oops - that first line of code should be
$m = new ArrayMath($timestamps);
and not
$m = new ArrayMath($labels); |
Re: Help with aggregate and addExtraField |
Posted by Peter Kwan on Dec-05-2011 00:15 |
|
Hi Warren,
For your case, as $overlay is an array of text string, there is no statistical aggregation possible (no SUM, AVERAGE, MIN, MAX, Standard Deviation, Percentile, etc). The only meaningful action is "resampling" (just get one of the value and discard all others, such as AggregateFirst). For this type of aggregation with "regular spacing", I think the easiest method is to simple use PHP code to aggregate the data. Personally, I think the coding should not be too "painful". In fact, I feel it is even simplier than using ArrayMath.
If I were to write the code, it would be like:
for ($i = 0; $i < count($timestamps); $i += 100) {
$aggregatedTimeStamps[] = $timeStamps[$i];
$aggregatedData[] = $data[$i];
$aggregatedOverlay[] = $overlay[$i];
}
Hope this can help.
Regards
Peter Kwan |
Re: Help with aggregate and addExtraField |
Posted by Warren on Dec-05-2011 17:31 |
|
Hi Peter
Thanks for the reply. The resampling idea is good - it may need some tweaks as the data
isn't a nice regular series, but I am sure I can get around that.
Regards
Warren |
|