javascript - Highcharts: Updating a Pie with ajax -



javascript - Highcharts: Updating a Pie with ajax -

i want update pie's info when li clicked. if data.php $cid value fixed value works. illustration : user_student.cid = 1 work. if utilize user_student.cid = $cid doesn't work. have idea?

thanks you,pquest.

but there have problems.if utilize fixed value 1 ,the alert value is: [["apple",1],["banana",2],["orange",3]] , pie working. if utilize $cid value(if $cid value 1) , value alert is:[["apple",1],["banana",2],["orange",3]] pie not working.

anyone have idea?

<script type="text/javascript"> $(document).ready(function() { $('table.display').datatable({ "paging": false, "info": false }); $('li').click(function(){ var cid = $(this).attr("id"); $.ajax({ type: "post", url: 'data.php', data:{ cid:cid }, success:function(reponse){ alert(reponse) /*options.series[0].data = reponse; chart = new highcharts.chart(options);*/ } }); var options = { chart: { renderto: 'pie', plotbackgroundcolor: null, plotborderwidth: null, plotshadow: false }, title: { text: 'web sales & marketing efforts' }, tooltip: { pointformat: '{series.name}: <b>{point.percentage}%</b>', percentagedecimals: 1, formatter: function() { homecoming '<b>'+ this.point.name +'</b>: '+ highcharts.numberformat(this.percentage, 1); +' %'; } }, plotoptions: { pie: { allowpointselect: true, cursor: 'pointer', datalabels: { enabled: true, color: '#000000', connectorcolor: '#000000', formatter: function() { homecoming '<b>'+ this.point.name +'</b>: '+ highcharts.numberformat(this.percentage, 1); +' %'; } } } }, series: [{ type: 'pie', datatype: 'json', name: 'browser share', data: [] }] } $.getjson("data.php", function(json) { options.series[0].data = json; chart = new highcharts.chart(options); }); }); }); </script>

data.php

<?php require_once("../connectdb.php"); $cid = isset($_post["cid"]) ? $_post["cid"] : ""; $result = $db->prepare("select stu_info.reference stu_info , user_student stu_info.sid = user_student.sid , user_student.cid = :cid"); $result ->execute(array(':cid' => $cid,)); $one = 0; $two = 0; $three = 0; while($r = $result -> fetch()) { if($r['reference'] === "apple") $one = $one+1; else if($r['reference'] === "banana") $two = $two+1; else if($r['reference'] === "orange") $three = $three+1; } $ra = array($one,$three,$two); $rb = array(apple,banana,orange); $rows = array(); for($i=0 ; $i<=2 ; $i=$i+1) { $row[0] = $rb[$i]; $row[1] = $ra[$i]; array_push($rows,$row); } print json_encode($rows, json_numeric_check); ?>

you cant write $cid in query text. have build string:

"select stu_info.reference stu_info , user_student stu_info.sid = user_student.sid , user_student.cid = " . $cid

edit: looks concatenation operator in php . rather +

javascript php jquery ajax highcharts

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -