Google chart timeline horizontal scroll

老子叫甜甜 提交于 2019-12-05 07:24:56

there are no standard configuration options on the Timeline chart for scroll nor zoom.

but you could use css for horizontal scroll

set a specific width in the chart options --> width: 1200

and wrap it in a container with a smaller width and --> overflow-x: scroll;

see following working snippet for an example...

google.charts.load('current', {
  callback: drawChart,
  packages: ['timeline']
});
function drawChart() {
  var container = document.getElementById('chart_div');
  var chart = new google.visualization.Timeline(container);
  var dataTable = new google.visualization.DataTable();

  dataTable.addColumn({ type: 'string', id: 'President' });
  dataTable.addColumn({ type: 'date', id: 'Start' });
  dataTable.addColumn({ type: 'date', id: 'End' });
  dataTable.addRows([
    [ 'Washington', new Date(1789, 3, 30), new Date(1797, 2, 4) ],
    [ 'Adams',      new Date(1797, 2, 4),  new Date(1801, 2, 4) ],
    [ 'Jefferson',  new Date(1801, 2, 4),  new Date(1809, 2, 4) ]]);

  chart.draw(dataTable, {
    width: 1200
  });
}
#chart_wrapper {
  overflow-x: scroll;
  overflow-y: hidden;
  width: 400px;
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_wrapper">
  <div id="chart_div"></div>
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!