Hello to all,
Recently I looked out the framework of this beautiful world and I’m here to ask for help!
In practice I have created a chart with the widget Highcharts and I wish you would update every few minutes automatically.
controll:
public function ActionUpdateAjax() {
$query = Yii::app()->db->createCommand()
->select('campo1,campo2')
->from('TabellaMia')
->queryAll();
$i = 0;
foreach ($query as $key => $value)
{
$colore = "red";
$c[]=array('name' => $query[$i]['Nome'],'y' => (double)$query[$i]['email'], 'color' => 'red' );
$i++;
}
IF ($c == "") {
$colore = "#66FF00";
$c[]=array('name' => 'Servizio','y' => 30, 'color' => $colore );
}
$c["ciao"] = $c;
$this->renderPartial('new2',$c, false, true);
new2:
$this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
#'chart'=> array('renderTo'=>'container'),
'title' => array('text' => 'ALLARMI'),
'credits' => array('enabled' => false),
'exporting' => array('enabled' => false),
'plotOptions' => array(
'pie' => array(
'renderTo'=>'container',
'allowPointSelect' => true,
'cursor' => 'pointer',
'dataLabels' => array(
'enabled' => true,
'color' => 'Black',
'connectorColor' => 'green',
'formatter' => "js:function(){return '<b>'+ this.point.name + ' </b>' + this.y + ' </b>' ;}",
),
)
),
'series' => array(array(
'animation' => false,
'name' => '%',
'type' => 'pie',
'data' => $ciao,
/* array(
'name' => array($c),
'y' => array($<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' />,
'color' => array($colore),
),*/
))
)
));
view:
$url=$this->createUrl('web/UpdateAjax');
Yii::app()->clientScript->registerScript("refresh","
function updateData()
{
$.ajax({
'url':'".$url."',
'success':function(data){
$('#data').html(data);
}
});
}
updateData();
var auto_refresh = setInterval(function(){
updateData()
}, 10000);
");
?>
<div id="data" method="post" class="block-content">
</div>
The first graph shows the refresh, but on the second lap disappears …!
where am I wrong?
thank you very much …