2014-05-20 56 views
0

我有一個Highchart折線圖,我想要4行出現,2將通過我擁有的MySQL數據庫表進行動態更新, GoogleCharts API,但最近我見過HighCharts,對此印象非常深刻。我已經配置了它的工作,但我只能用它來工作。我試圖向數組中添加新行,但我似乎無法看到行的繪製位置,因爲我是HighCharts的新手。我已經將它配置爲使用「DPMO」列,並且當我將1行更改爲2時,它會顯示我想用dpmo行顯示的我的平均線。結合兩條靜態線,一條是3000條,另一條是5000條。HighCharts Linechart多行的MySQL/PHP數據

謝謝。

IRDR.php文件

<head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <title>OAK3 - 12 Week IRDR DPMO</title> 
    <script type="text/javascript" src="js/jquery.min.js"></script> 
    <script type="text/javascript" src="js/setup.js"></script> 
    <script type="text/javascript" src="js/test.js"></script>  
</head> 

<body> 
    <script src="js/highcharts.js"></script> 
    <div id="sales" style="min-width: 310px; height: 400px; margin: 0 auto"></div> 
</body> 

Setup.js

var chart; 
    $(document).ready(function() { 
     var cursan = { 
      chart: { 
       renderTo: 'sales', 
       defaultSeriesType: 'line', 
       marginRight: 10, 
       marginBottom: 20 
      }, 
      title: { 
       text: 'IRDR 12 Week DPMO', 
      }, 
      subtitle: { 
       text: 'http://blackmesa.amazon.com', 
      }, 
      xAxis: { 
       categories: [] 
      }, 
      yAxis: { 
       title: { 
        text: 'DPMO' 
       }, 
       plotLines: [{ 
        value: 0, 
        width: 1, 
        color: '#808080' 
       }] 
      }, 
      tooltip: { 
       crosshairs: true, 
       shared: true 
      }, 
      legend: { 
       layout: 'vertical', 
       align: 'right', 
       verticalAlign: 'top', 
       x: -10, 
       y: 30, 
       borderWidth: 0 
      }, 

      plotOptions: { 

       series: { 
        cursor: 'pointer', 
        marker: { 
         lineWidth: 1 
        } 
       } 
      }, 

      series: [{ 
       color: Highcharts.getOptions().colors[2], 
       name: 'IRDR DPMO', 
       marker: { 
        fillColor: '#FFFFFF', 
        lineWidth: 3, 
        lineColor: null // inherit from series 
       }, 
       dataLabels: { 
        enabled: true, 
        rotation: 0, 
        color: '#666666', 
        align: 'top', 
        x: -10, 
        y: -10, 
        style: { 
         fontSize: '9px', 
         fontFamily: 'Verdana, sans-serif', 
         textShadow: '0 0 0px black' 
        } 
       } 
      }], 

     } 


     //Fetch MySql Records 
     jQuery.get('js/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/); 
        dpmo = line[0]; 
        average = line[1]; 
        amo=parseFloat(line[1].replace(',', '')); 
        if (isNaN(amo)) { 
         amo = null; 
        } 
        traffic.push([ 
         dpmo, 
         amo, 
         average 
        ]); 
       }); 
      } catch (e) { } 
      cursan.series[0].data = traffic; 
      chart = new Highcharts.Chart(cursan); 
     }); 
}); 

Data.php(它從MySQL數據庫表我的數據拉)

<?php 

$con=mysql_connect('localhost','root','password'); 
mysql_select_db("test", $con); 
$result=mysql_query('select substr(process_name,11,15) as process_name, a.dpmo as dpmo, a.process_id as process_id, oak3_ia.dpmo as average from (select * from oak3_irdr_chart order by process_id desc limit 12)a left join oak3_irdr_average oak3_ia on oak3_ia.process_id = a .process_id order by process_id'); 
while($row = mysql_fetch_array($result)) { 
    echo $row['process_name'] . "\t" . $row['dpmo']. "\t" . $row['average']. "\n"; 
} 

?> 

電流輸出: enter image description here

預期輸出: enter image description here

回答

1

因爲你應該設置在系列對象系列的多個陣列,但你有一個單一系列:cursan.series[0].data = traffic;它意味着你有串聯,這是一個系列單個對象。

+0

謝謝你的迴應。你會推薦我怎麼改正這個? cursan.series [0] .data = traffic;這應該改爲[]嗎?或者我將不得不在其他地方定義數組?對不起,我的noob反應,我沒有太多的這種製圖API的經驗。 – Spartacus38