大家好,感谢阅读我正在徘徊如何将动态数据插入到 highcharts 扩展中,例如我有如下的 highcharts 扩展(代码位置 => Reprting/index):
$this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
'credits' => array('enabled' => false),
'title' => array('text' => $graphTitle),
'xAxis' => array(
'categories' => array('Apples', 'Bananas', 'Oranges')
),
'yAxis' => array(
'title' => array('text' => 'Fruit eaten')
),
'series' => array(
array('name' => 'Jane', 'data' => array(3, 6, 7)),
array('name' => 'John', 'data' => array(5, 7, 3))
) )));
我在控制器中有以下代码:
public function actionIndex()
{
$model= $this->loadModel();
$dataProvider=new CActiveDataProvider('Reporting');
$graphTitle= 'Price Per Product';
$this->render('index',array(
'dataProvider'=>$dataProvider, 'graphTitle'=>$graphTitle, 'model'=>$model,
));
}
以下代码是模型:
class Reporting extends CActiveRecord
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{price}}';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('id_product, id_channel', 'required'),
array('id_product, id_channel', 'numerical', 'integerOnly'=>true),
array('price_min, price_max', 'numerical'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id_price, id_product, id_channel, price_min, price_max', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'idChannel' => array(self::BELONGS_TO, 'Channel', 'id_channel'),
'idProduct' => array(self::BELONGS_TO, 'Product', 'id_product'),
);
}
public function attributeLabels()
{
return array(
'id_price' => __('Id Price'),
'id_product' => __('Id Product'),
'id_channel' => __('Id Channel'),
'price_min' => __('Price Min'),
'price_max' => __('Price Max'),
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id_price',$this->id_price);
$criteria->compare('id_product',$this->id_product);
$criteria->compare('id_channel',$this->id_channel);
$criteria->compare('price_min',$this->price_min);
$criteria->compare('price_max',$this->price_max);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
我如何将所有这些放在一起以实现动态驱动图