2016-10-03 24 views
1

我使用phantomjs和highcharts-convert.js在服務器上呈現圖像。我有名爲data.json的JSON腳本。如何從mysql的highcharts-convert.js中獲取系列和類別的數據

{ 
chart: { 
    backgroundColor: '#4A4D4E', 
    type: 'column' 
}, 
xAxis: { 
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
     'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 
    labels: { 
     formatter: function() { 
      return '<span style="fill: white;">' + this.value + '</span>'; 
     } 
    } 
}, 
yAxis: { 
    min: 0 
}, 
series: [{ 
    name: 'Total Interaction', 
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 
     135.6, 148.5, 216.4, 194.1, 95.6, 54.4], 
    color: 'red' 
}] 

};

我在cmd中

phantomjs highchart-convert.js -infile data.json -outfile image.png 

運行此腳本,這成功生成image.png,但我想要的類別和系列從另一個JSON是從執行這樣

[{"name":"Date","data":["December","January","February","March","April"]}, {"name":"Interaction","data":["99621","148350","107637","113887","103831"]}] 
PHP腳本的結果,可以採取

那麼我怎麼能得到這個?

+0

在highcharts-convert中沒有這樣做的設置,您需要向highchatrs添加新功能 - 轉換或構建data.json,並在使用highcharts-轉換。 –

回答

0

從data.json中讀取數據並設置一個對象,例如, 「數據」。 從php中讀取數據並設置對象,例如「系列」。 用腳本中的系列替換數據中的系列。 保存新數據。 用新數據調用命令行語句。

// I'm harcoding but you get the data from data.json 
var data = { 
chart: { 
    backgroundColor: '#4A4D4E', 
    type: 'column' 
}, 
xAxis: { 
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
     'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 
    labels: { 
     formatter: function() { 
      return '<span style="fill: white;">' + this.value + '</span>'; 
     } 
    } 
}, 
yAxis: { 
    min: 0 
}, 
series: [{ 
    name: 'Total Interaction', 
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 
     135.6, 148.5, 216.4, 194.1, 95.6, 54.4], 
    color: 'red' 
}]}; 

// It's harcoded but you must get the data from the script 
var series = [{"name":"Date","data":["December","January","February","March","April"]}, {"name":"Interaction","data":["99621","148350","107637","113887","103831"]}]; 
// Replace the series 
data.series = series; 

// save data as data2.json 
// call in command line: phantomjs highchart-convert.js -infile data2.json -outfile image.png 
相關問題