2014-03-27 71 views
1

我們在我們的網站上有Google Graph,一切工作正常,但我的客戶正在請求我們是否可以有從右到左的日期。谷歌圖形API從左到右更改x軸從右到左

我經歷了Google API,因爲我沒有找到任何關於此的內容,他們似乎也沒有解決這個問題。

實施例:

Currently its like this 
27th 26th 25th 24th 23rd 

It should be like this 
23rd 24th 25th 26th 27th 

我還附上它的屏幕截圖。

JS

<script type="text/javascript"> 
    google.load("visualization", "1", {packages:["corechart"]}); 
    google.setOnLoadCallback(drawChart); 
    function drawChart() { 
    var data = google.visualization.arrayToDataTable([ 
     ['', 'Current Demand'], 
     <?php echo $data; ?> 
    ]); 

    var options = { 
      width: 390, 
      height: 261, 
      isStacked: true, 
      legend: 'none', 
      colors: ['#fff'], 
      backgroundColor: {fill:'transparent' }, 
      vAxis: {textColor: '#ffffff', title: '', titleTextStyle: {color: 'white'}}, 
      hAxis: {textColor: '#ffffff', title: '', titleTextStyle: {color: 'white'}} 
    } 

    var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); 
    chart.draw(data, options); 
    } 
</script> 

PHP

<?php 
     global $post; 
     $args = array(
      'order' => 'DESC', 
      'orderby' => 'post_date', 
      'post_status' => 'publish', 
      'post_type' => 'demand', 
      'showposts' => 5 
     ); 
     if (have_posts()): 
      $list_of_posts = new WP_Query($args); 
       while ($list_of_posts->have_posts()):$list_of_posts->the_post(); 

        $the_post = get_post($post->ID); 
        $date = $the_post->post_date; 
        $date = date("dS M", strtotime($date)); 

        $current_demand = get_metadata('post', $post->ID, 'current_demand'); 
        $current_demand = $current_demand[0]; 

        //$maximum_supply = get_metadata('post', $post->ID, 'maximum_supply'); 
        //$maximum_supply = $maximum_supply[0]; 

        $data .= "['$date', $current_demand],"; 
       endwhile; 
     endif; 
     // Remove the extrea comma from the array which was created above. 
     $data = rtrim($data, ','); 
?> 

enter image description here

+0

只是解析reveresed數據 – 2014-03-27 02:19:20

回答

2

有在谷歌圖表API沒有選項。但是你可以通過改變在php代碼中從數據庫獲取記錄的順序來實現這一點。 您可能需要更改

'order' => 'DESC','order' => 'ASC',