I want to create a bar chart in a system which is based on zend framework, I found this jqPlot as a good way to do that. But I can not understand how to map this with MVC layout and again how can I use an array to pass the data extracted from zend model to the javascript function in zend view? I tried so many ways but could not get the required result.
You can use AJAX data renderer for jqPlot. Then you should generate data in your logic/model class and fetch it by retrieving data from controller action.
<div id="sharechart"></div>
(don't forget to include scripts required by jqPlot)
<script type="text/javascript">
var ajaxShare = function() {
var data = null;
$.ajax({
async: false,
url: '<?php echo $this->baseUrl(); ?>/charts/getshare',
dataType: 'json',
success: function(response) {
data = response;
},
});
return data;
};
$.jqplot('sharechart', {
title: '<h1>Bank share</h1>',
seriesDefaults: {
renderer: $.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true,
dataLabels: 'label',
}
},
legend: { show:true, location: 'e' },
dataRenderer: ajaxShare,
});
</script>
public function getshareAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$logic = new My_Charts();
$shareArray = $logic->getShareData();
echo json_encode(array($shareArray));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.