2018-05-29 08:49
浏览 71

从Laravel / PHP解析Google Chart Timeline的数据

Here is the sample code from Google Charts Timeline with static data. I am wondering how to add dataRows from a Laravel dataset.

    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

<script type="text/javascript">
  google.charts.load("current", {packages:["timeline"]});
  function drawChart() {
    var container = document.getElementById('example5.3');
    var chart = new google.visualization.Timeline(container);
    var dataTable = new google.visualization.DataTable();
    dataTable.addColumn({ type: 'string', id: 'Room' });
    dataTable.addColumn({ type: 'string', id: 'Name' });
    dataTable.addColumn({ type: 'date', id: 'Start' });
    dataTable.addColumn({ type: 'date', id: 'End' });
      [ 'Magnolia Room',  'CSS Fundamentals',    new Date(0,0,0,12,0,0),  new Date(0,0,0,14,0,0) ],
      [ 'Magnolia Room',  'Intro JavaScript',    new Date(0,0,0,14,30,0), new Date(0,0,0,16,0,0) ],
      [ 'Magnolia Room',  'Advanced JavaScript', new Date(0,0,0,16,30,0), new Date(0,0,0,19,0,0) ],

    var options = {
      timeline: { colorByRowLabel: true },
      backgroundColor: '#ffd'

    chart.draw(dataTable, options);

<div id="example5.3" style="height: 150px;"></div>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutan1857 2018-06-06 08:46

    Found a perfect solution from another thread. Modified the code to fit in Laravel

    Using timeline Google Chart API in PHP - Date/Time formatting issues

    打赏 评论

相关推荐 更多相似问题