2016-09-13 45 views
0

大家好我是新使用highcharts,我有我的數據結構,當我試圖表明,我沒有看到任何使用Highcharts API爲呈現倍數值

function nueva (current_data){ 
    var seriesOptions = [], 
    seriesCounter = 0, 
    type = ['jobs_running', 'jobs_pending']; 
    function createChart() { 
     $('#containerChart').highcharts('StockChart', { 
     rangeSelector: { 
      selected: 4 
     }, 
     tooltip: { 
      pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>', 
      valueDecimals: 2 
     }, 
      series: seriesOptions 
     }); 
    } 
    for (var j = 0; j < current_data['names'].length; j++){ 
     var all_element = [] 
     name_project = current_data['names'][j]; 
     for (var i = 0; i < type.length; i++){ 
     seriesCounter = 0; 
     for (var i = 0; i < type.length; i++){ 
      seriesOptions[j] = { 
       name: type[i], 
       data: current_data[name_project][type[i]], 
      }; 
     } 
     } 
     createChart(); 
    } 
    } 

我通過current_data我的功能就是這樣

enter image description here

我想顯示 'jobs_running' 和 'jobs_pendding' 我的值設置爲seriesOptions

enter image description here

和我的數據的陣列有這個

enter image description here

任何想法,爲什麼我沒有看到圖中的東西!我錯過了一些東西。

在此先感謝

+0

控制檯中是否有錯誤?你能發表你的問題的現場例子嗎? –

回答

2

希望你可以在此找到答案:

https://jsfiddle.net/ekekp8rh/1/

不知道你是希望得到,但至少這將顯示一個圖表。

var data = { 
projects: [{ 
    name: 'Project X', 
    jobs_running: [ 
     [1459814400000, 121], 
     [1459900800000, 205], 
     [1459987200000, 155], 
     [1460073600000, 458] 
    ], 
    jobs_pending: [ 
     [1459814400000, 146], 
     [1459900800000, 149], 
     [1459987200000, 158], 
     [1460073600000, 184] 
    ] 
    }, { 
    name: 'Project Y', 
    jobs_running: [ 
     [1459814400000, 221], 
     [1459900800000, 295], 
     [1459987200000, 255], 
     [1460073600000, 258] 
    ], 
    jobs_pending: [ 
     [1459814400000, 246], 
     [1459900800000, 249], 
     [1459987200000, 258], 
     [1460073600000, 284] 
    ] 
    }] 
}; 
nueva(data); 

function nueva(current_data) { 
    var seriesOptions = [], 
    type = ['jobs_running', 'jobs_pending']; 
    for (var j = 0; j < current_data['projects'].length; j++) { 
    var project = current_data['projects'][j]; 
    for (var i = 0; i < type.length; i++) { 
     seriesOptions.push({ 
     name: project.name + ' ' + type[i], 
     data: project[type[i]] 
     }); 
    } 
    } 
    $('#containerChart').highcharts('StockChart', { 
    series: seriesOptions 
    }); 
} 
相關問題