Google 图表时间线水平滚动
Google chart timeline horizontal scroll
我有一个时间线图表,与本页的第一个示例非常相似 (https://developers.google.com/chart/interactive/docs/gallery/timeline)。
我在 Y 轴上有活动(做午餐、吃饭、ecc),在 X 轴上我有时间。
我想启用水平滚动和图表缩放in/out(如本主题所述)。但我似乎无法让它工作。
有什么方法可以在时间线图表上启用水平滚动吗?
非常感谢。
亚历山德罗
没有用于滚动和缩放的标准 configuration options on the Timeline 图表。
但您可以使用 css 进行水平滚动
在图表选项中设置特定宽度 --> width: 1200
并将其包裹在宽度较小的容器中 --> overflow-x: scroll;
有关示例,请参见以下工作片段...
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>
我有一个时间线图表,与本页的第一个示例非常相似 (https://developers.google.com/chart/interactive/docs/gallery/timeline)。
我在 Y 轴上有活动(做午餐、吃饭、ecc),在 X 轴上我有时间。
我想启用水平滚动和图表缩放in/out(如本主题所述
有什么方法可以在时间线图表上启用水平滚动吗?
非常感谢。
亚历山德罗
没有用于滚动和缩放的标准 configuration options on the Timeline 图表。
但您可以使用 css 进行水平滚动
在图表选项中设置特定宽度 --> width: 1200
并将其包裹在宽度较小的容器中 --> overflow-x: scroll;
有关示例,请参见以下工作片段...
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>