多系列Highcharts没有绘制图形,json格式?

时间:2014-07-12 11:49:16

标签: json database highcharts

我试图获取一些数据库临时值来绘制图形,但似乎json格式不适合渲染,(可能是带引号的东西?)但似乎无法解决问题,任何帮助都会指向正确的方向将受到极大的关注。

很想看到在xasis上绘制的日期/时间数据

这是我的代码 html图

   <!DOCTYPE HTML>
     

                         Groendak

   <script type="text/javascript"   
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
   <script type="text/javascript">
     

$(function(){      var chart;      $(document).ready(function(){          $ .getJSON(“data3.php”,function(json){

       chart = new Highcharts.Chart({
           chart: {
              renderTo: 'container',  
             type: 'line',
               marginRight: 130,
               marginBottom: 25
           },
           title: {
               text: 'Sensor1 vs. Sensor2',
               x: -20 //center
           },
           subtitle: {
               text: '',
               x: -20
           },
           xAxis: {


   },
          yAxis: {
               title: {
                   text: 'Temperatuur'
               },
               plotLines: [{
                   value: 0,
                   width: 1,
                   color: '#808080'
               }]
           },
           tooltip: {
               formatter: function() {
                       return '<b>'+ this.series.name +'</b><br/>'+
                       this.x +': '+ this.y;
               }
           },
           legend: {
               layout: 'vertical',
               align: 'right',
               verticalAlign: 'top',
               x: -10,
               y: 100,
               borderWidth: 0
           },
           series: json
       });
   });
     

});

     

});                             

           

      

data3.php部分

  $series3['data'][] = $r['sensor10']; $series4['data'][] = $r['time'];      }      $ result = array();   array_push($结果,$类);      array_push($结果,$系列1);      array_push($结果,$系列3);   array_push($结果,$系列4);      print json_encode($ result,JSON_NUMERIC_CHECK);      mysql_close($ CON);   ?&GT;

和我从data3.php获得的json数据

    [{"name":"sensor1","data":[" 245 "," 245 "," 286 "," 289 "," 292 "," 290 "," 289 "," 287 "," 288 "," 286 "," 281 "," 279 "," 280 "," 277 "," 272 "," 270 "," 270 "," 267 "," 265 "," 264 "," 263 "," 260 "," 258 "," 259 "," 258 "," 257 "," 255 "," 252 "," 251 "," 252 "," 248 "," 247 "," 245 "," 244 "," 241 "," 239 "," 241 "," 237 "," 238 "," 234 "," 235 "," 234 "," 232 "," 230 "," 229 "," 230 "," 228 "," 228 "," 228 "," 227 "," 225 "," 226 "," 224 "," 225 "," 224 "," 223 "," 220 "," 220 "," 222 "," 222 "," 218 "," 220 "," 220 "," 218 "," 219 "," 218 "," 217 "," 219 "," 218 "," 216 "," 218 "," 215 "," 217 "," 218 "," 214 "," 216 "," 214 "," 214 "," 217 "," 214 "," 215 "," 214 "," 216 "," 215 "," 214 "," 217 "," 215 "," 215 "," 215 "," 216 "," 218 "," 217 "," 218 "," 219 "," 219 "," 221 "," 220 "," 221 "," 224 "," 225 "," 224 "," 226 "," 225 "," 228 "," 229 "," 229 "," 231 "," 230 "," 230 "," 231 "," 232 "]},{"name":"sensor2","data":[" 313 "," 312 "," 291 "," 285 "," 277 "," 278 "," 273 "," 271 "," 266 "," 261 "," 261 "," 258 "," 251 "," 249 "," 251 "," 249 "," 245 "," 243 "," 243 "," 239 "," 237 "," 239 "," 238 "," 232 "," 230 "," 229 "," 229 "," 230 "," 229 "," 223 "," 225 "," 222 "," 220 "," 217 "," 219 "," 219 "," 212 "," 216 "," 210 "," 214 "," 209 "," 209 "," 209 "," 210 "," 209 "," 206 "," 206 "," 204 "," 202 "," 202 "," 204 "," 199 "," 200 "," 197 "," 195 "," 196 "," 199 "," 198 "," 193 "," 192 "," 197 "," 193 "," 192 "," 195 "," 192 "," 194 "," 195 "," 191 "," 191 "," 193 "," 191 "," 196 "," 192 "," 193 "," 198 "," 196 "," 200 "," 200 "," 199 "," 204 "," 204 "," 208 "," 206 "," 209 "," 214 "," 211 "," 218 "," 221 "," 224 "," 227 "," 228 "," 233 "," 236 "," 239 "," 244 "," 248 "," 252 "," 255 "," 255 "," 258 "," 266 "," 266 "," 273 "," 271 "," 273 "," 278 "," 279 "," 284 "," 288 "," 291 "," 291 "]},{"name":"sensor10","data":[" 240 "," 178 "," 187 "," 198 "," 201 "," 204 "," 203 "," 189 "," 186 "," 188 "," 191 "," 193 "," 195 "," 203 "," 198 "," 196 "," 196 "," 196 "," 195 "," 196 "," 196 "," 197 "," 196 "," 193 "," 190 "," 192 "," 194 "," 194 "," 194 "," 189 "," 183 "," 180 "," 180 "," 180 "," 180 "," 178 "," 177 "," 180 "," 182 "," 184 "," 184 "," 184 "," 184 "," 184 "," 183 "," 183 "," 182 "," 182 "," 180 "," 182 "," 181 "," 180 "," 180 "," 180 "," 180 "," 182 "," 182 "," 182 "," 181 "," 183 "," 183 "," 182 "," 182 "," 181 "," 181 "," 182 "," 183 "," 184 "," 185 "," 186 "," 186 "," 188 "," 191 "," 199 "," 202 "," 200 "," 202 "," 203 "," 209 "," 206 "," 210 "," 210 "," 206 "," 214 "," 224 "," 234 "," 235 "," 238 "," 232 "," 247 "," 276 "," 277 "," 255 "," 243 "," 242 "," 257 "," 242 "," 254 "," 258 "," 269 "," 264 "," 265 "," 254 "," 263 "," 278 "," 277 "," 259 "," 259 "," 266 "," 278 "," 284 "]},{"name":"time","data":[" 2014-07-10 19:26:52"," 2014-07-10 19:36:52"," 2014-07-10 19:46:52"," 2014-07-10 19:56:52"," 2014-07-10 20:06:52"," 2014-07-10 20:16:52"," 2014-07-10 20:26:52"," 2014-07-10 20:36:52"," 2014-07-10 20:46:52"," 2014-07-10 20:56:52"," 2014-07-10 21:06:52"," 2014-07-10 21:16:52"," 2014-07-10 21:26:52"," 2014-07-10 21:36:53"," 2014-07-10 21:46:53"," 2014-07-10 21:56:53"," 2014-07-10 22:06:53"," 2014-07-10 22:16:53"," 2014-07-10 22:26:53"," 2014-07-10 22:36:53"," 2014-07-10 22:46:53"," 2014-07-10 22:56:53"," 2014-07-10 23:06:53"," 2014-07-10 23:16:54"," 2014-07-10 23:26:54"," 2014-07-10 23:36:54"," 2014-07-10 23:46:54"," 2014-07-10 23:56:54"," 2014-07-11 00:06:54"," 2014-07-11 00:16:54"," 2014-07-11 00:26:54"," 2014-07-11 00:36:54"," 2014-07-11 00:46:54"," 2014-07-11 00:56:54"," 2014-07-11 01:06:54"," 2014-07-11 01:16:54"," 2014-07-11 01:26:54"," 2014-07-11 01:36:55"," 2014-07-11 01:46:55"," 2014-07-11 01:56:55"," 2014-07-11 02:06:55"," 2014-07-11 02:16:55"," 2014-07-11 02:26:55"," 2014-07-11 02:36:55"," 2014-07-11 02:46:55"," 2014-07-11 02:56:55"," 2014-07-11 03:06:55"," 2014-07-11 03:16:55"," 2014-07-11 03:26:56"," 2014-07-11 03:36:56"," 2014-07-11 03:46:56"," 2014-07-11 03:56:56"," 2014-07-11 04:06:56"," 2014-07-11 04:16:56"," 2014-07-11 04:26:56"," 2014-07-11 04:36:56"," 2014-07-11 04:46:56"," 2014-07-11 04:56:56"," 2014-07-11 05:06:56"," 2014-07-11 05:16:56"," 2014-07-11 05:26:56"," 2014-07-11 05:36:56"," 2014-07-11 05:46:56"," 2014-07-11 05:56:57"," 2014-07-11 06:06:57"," 2014-07-11 06:16:57"," 2014-07-11 06:26:57"," 2014-07-11 06:36:57"," 2014-07-11 06:46:57"," 2014-07-11 06:56:57"," 2014-07-11 07:06:57"," 2014-07-11 07:16:57"," 2014-07-11 07:26:57"," 2014-07-11 07:36:57"," 2014-07-11 07:46:57"," 2014-07-11 07:56:58"," 2014-07-11 08:06:58"," 2014-07-11 08:16:58"," 2014-07-11 08:26:58"," 2014-07-11 08:36:58"," 2014-07-11 08:46:58"," 2014-07-11 08:56:58"," 2014-07-11 09:06:58"," 2014-07-11 09:16:58"," 2014-07-11 09:26:58"," 2014-07-11 09:36:58"," 2014-07-11 09:46:58"," 2014-07-11 09:56:58"," 2014-07-11 10:06:58"," 2014-07-11 10:16:58"," 2014-07-11 10:26:59"," 2014-07-11 10:36:59"," 2014-07-11 10:46:59"," 2014-07-11 10:56:59"," 2014-07-11 11:06:59"," 2014-07-11 11:16:59"," 2014-07-11 11:26:59"," 2014-07-11 11:36:59"," 2014-07-11 11:46:59"," 2014-07-11 11:56:59"," 2014-07-11 12:07:00"," 2014-07-11 12:17:00"," 2014-07-11 12:27:00"," 2014-07-11 12:37:00"," 2014-07-11 12:47:00"," 2014-07-11 12:57:00"," 2014-07-11 13:07:00"," 2014-07-11 13:17:00"," 2014-07-11 13:27:00"," 2014-07-11 13:37:00"," 2014-07-11 13:47:00"]}]        

解析器

   <?php
     

$ con = mysql_connect('localhost','root','xxxxx');

     

if(!$ con){     死('无法连接:'。mysql_error());   }

     

mysql_select_db(“groendak”,$ con);

     

$ query = mysql_query(“SELECT sensor1,sensor2,sensor10,time FROM opstelling1”);

     

$ category = array();   $ category ['name'] ='sensor1';

     

$ series1 = array();   $ series1 ['name'] ='sensor2';

     

$ series3 = array();   $ series3 ['name'] ='Buiten Lucht';

     

$ series4 = array();   $ series4 ['name'] ='时间';

     

while($ r = mysql_fetch_array($ query)){       $ category ['data'] [] = intval($ r ['sensor1']);       $ series1 ['data'] [] = intval($ r ['sensor2']);       $ series3 ['data'] [] = intval($ r ['sensor10']);
      $ series4 ['data'] [] = 1000.0 * strtotime($ r ['time']);
  }

     

$ result = array();   array_push($结果,$类);   array_push($结果,$系列1);   array_push($结果,$系列3);   array_push($结果,$系列4);

     

print json_encode($ result,JSON_NUMERIC_CHECK);

     

mysql_close($ CON);   ?&GT;

0 个答案:

没有答案