JQuery -- an invalid solution for processing returned data using eval on the jqChart line chart. jqchartjquery
Jquery beginners
I checked a lot of posts. When the jqchart plug-in made a line chart, it was all eval when processing the returned data, but I couldn't figure it out. Later I found:
1. There is no need for eval processing at all. Just extract the string directly (the return value must be spliced );
2. Add the processed string to the data in series [];
The following code is used:
Only one <div id = "jqChart"> <script type = "text/javascript" src = "jquery.1.8.2.js"> </script> <script type = "text/javascript" src = "jquery-jqChart-min.js"> </script> <script type = "text/javascript"> $ (function () {$. get ("tgajax. php ", function (data) {var dom = data. substring (0, data. length-1); // mainly processing the returned data, followed by a "," // var dom = eval ('+ dom + ') '); // alert (dom); $ (' # jqchart '). jqChart ({title: {text: 'line chart example'}, axes: [{location: 'left', minimum: 1, maximum: 10, interval: 1,}], series: [{type: 'line', title: 'shanghai', markers: null, // do not mark the inflection point strokeStyle: 'blue', data: [['json ', 1], ['per', 9], ['perter ', 3]}, {type: 'line', // line, Column title: 'beijing ', strokeStyle: 'red', data: [dom]},]}) ;});
</Script>
I used simple php to process the page in the background. Nothing else will happen.
<? Phpinclude ("configaz. php "); // when the database is connected to another file, $ SQL =" select sid, sname, sprice, count (sprice) will not be obtained here) as pricenum from shangpin group by sname "; $ query = mysql_query ($ SQL); $ row = mysql_fetch_array ($ query); while ($ row = mysql_fetch_array ($ query )) {$ pricenum = $ row ['pricenum']; $ sname = $ row ['sname'];} echo $ str. = "['". $ sname. "',". $ pricenum. "],"; // concatenate strings in the string format required by jqChart. Of course, it is better to use arrays.
There must be a better way, but I just started learning and slowly explored.