jquery code
$("#pendingChart").sparkline([9, 11, 12, 13, 12, 13, 10], {
type: 'bar',
width: '100',
barWidth: 6,
height: '45',
barColor: '#5C9BD1',
negBarColor: '#e02222'
});
This works fine and produce a graphical chart. But I want to produce the data [9, 11, 12, 13, 12, 13, 10] from controller and pass to the jquery code. My controller section is okay. Here is the code:
function loadPointChart() {
$reseller = $this->Auth->user();
if (count($reseller) > 0) {
$api_key = $reseller['api_key'];
$this->loadModel('Order');
// $info=$this->Order->find('all','conditions' => array('api_key'=>$api_key));
$sql = "SELECT orders.id,orders.modified,orders.status,order_products.* FROM orders
LEFT JOIN order_products ON orders.id=order_products.order_id
WHERE orders.api_key = '$api_key' ORDER BY orders.modified ASC";
$infos = $this->Order->query($sql);
$return['points'] = $this->pointsCalculate($infos);
$penaltyChart = json_encode($return['points']['penalty']);
$pendingChart = json_encode($return['points']['pending']);
$successChart = json_encode($return['points']['success']);
echo $penaltyChart;
$this->set(compact('penaltyChart'));
}
}
echo echo $penaltyChart; is printing exact format data which I need: [4,3]
But I would I manipulate this data into my jquery code. I called this function inside before filter so that variable is initialized before page rendered.
to load data into jquery section I tried as follows:
$("#penaltyChart").sparkline(<?php echo $penaltyChart; ?>, {
type: 'bar',
width: '100',
barWidth: 6,
height: '45',
barColor: '#F36A5B',
negBarColor: '#e02222'
});
It gives error: Uncaught SyntaxError: Unexpected token < . Any idea?
It does not workis not a proper problem description. What does the generated source look like? What does happen? What errors are thrown?