2017-05-30 42 views
1

所以我試圖按分鐘顯示一些統計信息,但圖表......它看起來不對,或者我錯了嗎? enter image description here爲什麼我的谷歌圖表看起來不對

我有一個的jsfiddle這裏的例子:https://jsfiddle.net/p0j5qfL9/1/

google.charts.load('current', {packages: ['corechart', 'line']}); 
google.charts.setOnLoadCallback(load_page_data); 

function load_page_data(zoom,action,time,entry_id){ 

    zoom = typeof zoom !== 'undefined' ? zoom : 'date'; 
    action = typeof action !== 'undefined' ? action : 'banner view'; 
    time = typeof time !== 'undefined' ? time : $('.actions_logs .sort_time').val(); 
    entry_id = typeof entry_id !== 'undefined' ? entry_id : ''; 
    rows = []; 

    $.ajax({ 
     url: "/stats/get-stats", 
     data: {zoom : zoom, action : action, time: time, entry_id : entry_id}, 
     async: false, 
     success: function(data){ 
      if(data){ 
       var json = jQuery.parseJSON(data); 
       $.each(json, function(index, value) { 
        date = new Date(value.created); 
        rows.push([new Date(value.created),parseInt(value.total)]); 
       }); 

       drawBasic(rows,action,zoom); 
      } 
     } 
    }); 
} 

function drawBasic(rows,action,zoom) { 

    var data = new google.visualization.DataTable(rows); 
    column_type = (zoom == 'minute' || zoom == 'hour') ? 'datetime' : 'date'; 
    data.addColumn(column_type, 'Time of Day'); 
    data.addColumn('number', action); 


    data.addRows(rows); 

    var options = { 
     title: 'Action', 
     hAxis: { 
      title: 'Time', 
      format: (column_type == 'datetime') ? 'yyyy/M/d HH:mm' : null 
     }, 
     vAxis: { 
      title: 'Hits' 
     }, 
     pointSize: 5, 
     legend: { position: 'top', alignment: 'end' }, 
     animation: {"startup": true} 
    }; 

    var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
    $('.loading-chart').remove(); 
    chart.draw(data, options); 
} 

回答

0

由於varbrad說,你應該排序你的數據數組。根據數組的順序顯示這些點。

相關問題