JQuery -- an invalid solution for processing returned data using eval on the jqChart line chart. jqchartjquery

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.