Google Graph API从左到右,从右到左更改x轴

时间:2014-03-27 02:15:47

标签: php wordpress

我们的网站上有谷歌图表,一切正常,但我的客户要求我们是否可以从右到左提供日期。

我浏览了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

1 个答案:

答案 0 :(得分:2)

Google图表API中没有选项。但是你可以通过改变php代码中从db获取记录的顺序来实现这一点。 你可能需要改变

'order' => 'DESC',这个'order' => 'ASC',