I had the same problem and made a small work-around.
I created a new file in components called CompatibleFunctions.php.
<?php
/*
* To use the needed PHP 5.3 functions in a PHP 5.2 environment
*
*/
// as of PHP 5.3.0 array_replace_recursive() does the work for us
if (function_exists('array_replace_recursive'))
{
return call_user_func_array('array_replace_recursive', func_get_args());
}
if (!function_exists('array_replace_recursive'))
{
function array_replace_recursive($array, $array1)
{
function recurse($array, $array1)
{
foreach ($array1 as $key => $value)
{
// create new key in $array, if it is empty or not an array
if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key])))
{
$array[$key] = array();
}
// overwrite the value in the base array
if (is_array($value))
{
$value = recurse($array[$key], $value);
}
$array[$key] = $value;
}
return $array;
}
// handle the arguments, merge one by one
$args = func_get_args();
$array = $args[0];
if (!is_array($array))
{
return $array;
}
for ($i = 1; $i < count($args); $i++)
{
if (is_array($args[$i]))
{
$array = recurse($array, $args[$i]);
}
}
return $array;
}
}
?>
And added this file to be loaded in the index.php of Yii.
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
$compfunctions=dirname(__FILE__).'/protected/components/CompatibleFunctions.php';
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($compfunctions);
require_once($yii);
Yii::createWebApplication($config)->run();
Problem solved. After you upgrade to PHP 5.3 the original function will be used instead of this work-around one.
Thank you for the tip, Gaurav. That was an oversight on my part. I have updated the requirements section of the documentation and will add support for PHP 5.2 in the next release.
Here you go. The first 4 labels are cut off. At first I thought it was because of my use of a bar chart, so I’ve changed to a column chart. But as you can see, the problem is the same.
Edit:
It seems to be caused by differences in div sizes and SVG size.
Great extension for a very slick looking charting project.
I have a (hopefully?) quick question that I’m sure people have done. I’m still banging my head against it though, and in spite of tons of searching and reading and failed attempts, I can’t get it going.
Q: How do you get data from the database to a chart? I have a controller that returns a JSON-encoded string but I can’t get the Highchart example to use any data other than if it’s hard-coded just like the example. I’ve even created a local variable in PHP and tried to echo that to no avail.
I’ve also tried using the RequestData method on the ‘load’ event of the chart and can get data from my controller, but when I try to assign it to the widget ‘series’ it does nothing. I believe it’s because the chart itself isn’t declared as a global JavaScript variable, but I don’t see how the widget let’s me do that (in the Highcharts demo AJAX code it’s a simple assignment)
Anyone have a simple example of what the widget and controller action would look like?
Follow-up: I’ve gotten the categories part working, but can’t seem to get the series data populated. I’m trying to recreate the chart used in the wiki as an example. Thoughts on what I may be doing wrong? How do I tell the series to use the data from the controller in the same manner as I did for the categories?
Controller:
public function actionFruitCategories() {
$categories = array('Apples', 'Bananas', 'Oranges');
echo CJSON::encode($categories);
}
public function actionFruitData() {
$fruitData = array(
array('name' => 'Jane', 'data' => array(10, 0, 40)),
array('name' => 'John', 'data' => array(5, 70, 30))
);
echo CJSON::encode($fruitData);
}
I was able to get the charts working nicely from data extracted from a CActiveRecord. I was having some difficulty knowing exactly how to format the arrays used for the categories and the series, so I used the function
Print_r($arrayVariable)
to better understand the required format.
Since my data set was small (just the 12 months) and since I did not know another way, I just looped through the array of CActiveRecords and built up two arrays in a format that was required by the widget.