jquery - Flot Pie Chart with PHP -
i tried add load pie chart dynamically using flot chart , php/mysql.
this javascript code
<script id="source" language="javascript" type="text/javascript"> function fetchdata() { $.ajax({ url: "test.php", method: "get", datatype: "json", success: function(series) { var data = [ series ]; $.plot($("#graph1"), data, { pie: { show: true, showlabel: true }, legend: { show: false } }); } }); settimeout(fetchdata, 1000); } $(function () { $("#btn").click(function(){ fetchdata(); }); });
this php code
<?php include("db.php"); $return_arr = array(); $sql = mysql_query("select item, count(target) counter type='video' , date between '2011-02-21' , '2011-02-26' group target order id asc"); while($obj = mysql_fetch_object($sql)){ $return_arr[] = $obj; } echo json_encode($return_arr); ?>
this button
<input type="submit" value="click" id="btn"/>
this array when click button
[{"item":"final 2010","count(target)":"2"},{"item":"semi final 2009","count(target)":"3"}]
when click button, gives me error:
an invalid or illegal string specified" code: "12 [break on error] false
and pie chart not loading. can tell me did made wrong.
when check in firebug, array showing
[{"item":"final 2010","count(target)":"2"},{"item":"semi final 2009","count(target)":"3"}]
but when print it, shows [object object][object object], think problem, know how fix it
thanks
i think need eval data (series)
var data = eval("(" + series + ")");
that should it, think
edit
added simple replication on jsfiddle : http://jsfiddle.net/tvawl/1/
Comments
Post a Comment