2013-12-20 45 views
0

我正在创建漏斗图,它使用jquery.it从mysql表中获取数据。它在其他所有高图表上工作,但在漏斗图中失败。 这里是我的代码无法在高图中从mysql获取数据

的index.php

<script type="text/javascript" src="high-js/funnel-chart.js"></script>  
<div id="topcustomer" style="height: 500px;"></div> 

漏斗chart.js之

$(function() { 

    var curcust = new Highcharts.Chart({ 
     chart: { 
      renderTo:'topcustomer', 
      type: 'funnel', 
      marginRight: 100 
     }, 
     title: { 
      text: 'Top 5 Customer', 
      x: -50 
     }, 
     plotOptions: { 
      series: { 
       dataLabels: { 
        enabled: true, 
        format: '<b>{point.name}</b> ({point.y:,.0f})', 
        color: 'black', 
        softConnector: true 
       }, 
       neckWidth: '30%', 
       neckHeight: '25%' 

       //-- Other available options 
       // height: pixels or percent 
       // width: pixels or percent 
      } 
     }, 
     legend: { 
      enabled: false 
     }, 
     series: [{ 
      name: 'Current Month' 
     }] 
    }); 

    jQuery.get('data.php', null, function(tsv) { 
      var lines = []; 
      traffic = []; 
      try { 
       // split the data return into lines and parse them 
       tsv = tsv.split(/\n/g); 
       jQuery.each(tsv, function(i , line) { 
        line = line.split(/\t/); 
        cust = line[0] ; 
        traffic.push([ 
         cust, 
         line[1] 
        ]); 
       }); 
      } catch (e) { } 
      curcust.series[0].data = traffic; 
      chart = new Highcharts.Chart(curcust); 
     }); 
}); 

data.php

$result = mysql_query("SELECT customer, SUM(amount) AS amo FROM `yearly_sales` GROUP BY customer LIMIT 5"); 
while($row = mysql_fetch_array($result)) { 
     echo $row['customer'] . "\t" . $row['amo']. "\n"; 
} 

它不显示任何错误并且图表未生成。 在我的代码中是否有任何错误? 请帮我出这个问题感谢名单

回答

1

编辑 - PHP的应该是类似

$data = array(); 
while($row = mysql_fetch_array($result)) { 
     $data[] = array($row['customer'], $row['amo']); 
} 
echo json_encode($data); 

这仍然是一个有点混乱,但你可以尝试实例化的图表,你拥有的数据之后。

$(function() { 

    jQuery.get('data.php', null, function(tsv) { 
     var lines = []; 
     traffic = []; 
     try { 
      // split the data return into lines and parse them 
      tsv = tsv.split(/\n/g); 
      jQuery.each(tsv, function(i , line) { 
       line = line.split(/\t/); 
       cust = line[0] ; 
       traffic.push([ 
        cust, 
        line[1] 
       ]); 
      }); 
     } catch (e) { } 

     $('#topcustomer').highcharts({ 
      chart: { 
       type: 'funnel', 
       marginRight: 100 
      }, 
      title: { 
       text: 'Top 5 Customer', 
       x: -50 
      }, 
      plotOptions: { 
       series: { 
        dataLabels: { 
         enabled: true, 
         format: '<b>{point.name}</b> ({point.y:,.0f})', 
         color: 'black', 
         softConnector: true 
        }, 
        neckWidth: '30%', 
        neckHeight: '25%' 

        //-- Other available options 
        // height: pixels or percent 
        // width: pixels or percent 
       } 
      }, 
      legend: { 
       enabled: false 
      }, 
      series: [{ 
       name: 'Current Month', 
       data: traffic 
      }] 
     }); 
    }); 
}); 
+0

thanx @adamS但它也不起作用。 –

+0

查询的结果是什么。运行data.php并发布结果。 – adamS

+0

其结果如'公司1 31150.00 Company2 8480.00 Company3'3603370.50 Company4(POWER PROD.DIV)2241750.55 Company5 25657162.13 –