I’ve been using the Flash Chart Helper recently and it’s been working really well once I got a couple of things ironed out with it.
I followed the instructions and copied all the files to the right place. I had the array created and sending what I thought was the correct format of data to be graphed but I was still getting errors. Originally I had this line:
echo $flashChart->begin(array('prototype'=>true));
at the top of my graph. When I removed the option array (because I wasn’t using prototype) it gave me a lovely graph.
Next thing was add labels to the X-axis. My data set was being sent in the following format:
Array ( [0] => Array ( [day] => Monday [hits] => 0 ) [1] => Array ( [day] => Tuesday [hits] => 15 ) [2] => Array ( [day] => Wednesday [hits] => 58 ) [3] => Array ( [day] => Thursday [hits] => 23 ) [4] => Array ( [day] => Friday [hits] => 23 ) [5] => Array ( [day] => Saturday [hits] => 99 ) [6] => Array ( [day] => Sunday [hits] => 34 ) )
So I set up
echo $flashChart->setData($logs, '{n}.hits', '{n}.day', 'byDay'); echo $flashChart->axis('x', array('labels' => $logs));
To explain that, $logs is the array of data, {n}.hits is the data to be graphed, {n}.day is the label path, byDay is the name of the graph. The options for the axis are simply the array to pass in to read the labels from.
I then wanted the labels to be vertical so that they wouldn’t overlap. This proved to be a harder thing to fix. In the API on page three of the helper article, it only mentions
axis($axis, $options = array())
I added in the option of
'vertical' => true
but I got an error that the helper couldn’t find the set_vertical() function. After some digging around in the source, I found that the real way to pass label options was as a third variable to the axis function. So I edited my call to read
echo $flashChart->axis('x', array('labels' => $logs), array('vertical' => true);
and lo and behold, vertical labels!