1

I am not programmer and I am very new to Highcharts. Connection to the db works, the x,y axis of the chart and labels show up, but no data. I got this entire script from the Highchart's forum [here][1].

Question: How to I get the graph to show the data from the columns graduation_year and i_am_a_student?

I'm sure to the folks here it's a no-brainer, but to me it's a brick wall! TIA for any help anyone can send my way.

this is the complete script. I added the json bit as you suggested.

   <php
       $db = mysql_connect("localhost","un","pw","db");
   if ( $db == "" ) { echo " DB Connection error...\r\n"; exit(); }

   connects to db fine

   $sql = mysql_query($con,"SELECT graduation_year,i_am_a_student FROM wp_gfsept2013");
   $query = mysql_query($sql);

I think my problem is with the code below. I do not have the technical knowledge to modify it to display the data from my table. I've tried various things but no luck.

    $i = 0;
        while($row = mysql_fetch_array($query)){
             $date    = strtotime($row['date']);
             $stamp    = $date * 1000;
             $val    = (int)$row['value'];

             $d[$i]['x'] = $stamp;
             $d[$i]['y'] = $val;
             $i++;
          }
   echo json_encode($data, JSON_NUMERIC_CHECK);

   ?>

   <div id="container" style="width:800px;height:300px;margin:1em auto;"></div>

   <script type="text/javascript">
      $(document).ready(function() {
         var chart = new Highcharts.Chart({
            chart: {
               defaultSeriesType:'column',
               renderTo:'container'
            },
            credits:{enabled:false},
            title:{text:'Sample Chart'},
            legend:{
            },
            tooltip:{
            },
            plotOptions:{
               series:{
                  shadow:false,
                  borderWidth:0,
                  color:'rgba(90,155,212,.75)',
               }
            },
            xAxis:{
               title:{text:''},
               type:'datetime',
               lineWidth:1,
               lineColor:'#999',
               tickColor:'#999',
               tickLength:3,
            },
            yAxis:{
               lineWidth:1,
               lineColor:'#ccc',
               tickColor:'#999',
               tickLength:3,
               tickWidth:1,
               gridLineWidth:1,
               gridLineColor:'#e0e0e0',
               title:{text:''}
            },
            series:[{
          data: [<?php echo json_encode($data, JSON_NUMERIC_CHECK); ?>],
            }]
         });
      });
   </script>
   </body>
</html>
4

1 回答 1

0

Highcharts 使用数字值,所以我建议设置 JSON_NUMERIC_CHECK 标志以返回正确的值。如果它不能解决你的问题,请附上你使用的代码(不是来自 chrome 的源代码)但是你图表配置/获取 json 等。

于 2013-11-08T01:09:16.007 回答