简体   繁体   中英

json encode php and google charts

$data = '{ 
    "cols": [   {"id":"","label":"ID","pattern":"","type":"string"}, 
            {"id":"","label":"Instant Background","pattern":"","type":"number"}, 
            {"id":"","label":"Red","pattern":"","type":"number"}, 
            {"id":"","label":"Green","pattern":"","type":"number"}, 
            {"id":"","label":"Blue","pattern":"","type":"number"} 
        ],

    "rows": [
    {"c":[{"v":"827075"},{"v":3992},{"v":3989},{"v":3994},{"v":3993}]},
    {"c":[{"v":"827070"},{"v":3974},{"v":3987},{"v":3985},{"v":3985}]},
    {"c":[{"v":"827070"},{"v":3974},{"v":3987},{"v":3985},{"v":3985}]},
    {"c":[{"v":"827070"},{"v":3974},{"v":3987},{"v":3985},{"v":3985}]},
    {"c":[{"v":"827070"},{"v":3974},{"v":3987},{"v":3985},{"v":3985}]}
    ]
    }'; echo $data;

ok the data works witht the echo when used on the google maps in this format so there is no issue there.

function drawChart(jsonData) {
      jsonData = $.ajax({
      url: "http://www.mailboxmbe.com/jsongraph.php",
      dataType:"json",
      async: false
      }).responseText;

PHP gets the data from an SQl statement and constructs the data as such:

$JSONObject1 = '{"c":[{"v":"'.$row["id"].'"},{"v":'.$row["sinstantBackground"].'},{"v":'.$row["sRed"].'},{"v":'.$row["sGreen"].'},{"v":'.$row["sBlue"].'}]},'.$JSONObject1;

Each Row has the following id,sinstantBackground,sRed,sGreen.sBlue.

On the the Graph page jsonData holds the json string passed to it from the echo $data which is called via the SQL query.

What I would like to do is work out how to turn the json script in jsonData into a format where i can find out what the largest ID is?

Not sure to understand the question but creating a DataTable should be enough :

var data = new google.visualization.DataTable(jsonData);

Then have a look to the different accessor methods here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM