Привет всем, спасибо за чтение, я блуждал, как вы можете вставлять динамические данные в расширение высокой чарты, например, у меня есть расширение для высоких диаграмм следующим образом (расположение кода => Повторная пересылка/индекс):Использование yii с динамическими данными и высокими диаграммами
$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,
));
}
}
Как я положил все это вместе, чтобы достичь динамически Driven граф
спасибо за вдохновение, полезно, но я блуждал, как хранить переменные в запросе, а затем отображать их на графике – Gunnit
Добро пожаловать. Мое предложение - использовать статический метод findAll класса Reporting для извлечения всех ваших объектов (учитывая тот факт, что вы не применяете никаких ограничений на CActiveDataProvider), и создайте два массива в контроллере, итерации по результатам. HighchartsWidget не поддерживает чтение данных из «dataProvider». – sucotronic