我正在研究 angularjs 谷歌图表。我想显示图表的水平滚动条,默认情况下它应该从右向左滚动。
示例演示 http://jsfiddle.net/uzbozqz4/
为了使滚动条默认从右向左滚动,我使用了下面在 style 属性中定义的 CSS 代码:
<div id="chart_div" style="margin-left:0;white-space: nowrap;overflow-x:auto;overflow-y:hidden;direction:rtl;left:0;top:0;height: 500px;"></div>
direction:rtl
使滚动条从右向左滚动,这是必需的,但问题是我可以看到从右向左滚动时左侧有很多空白。我尝试使用 left-padding:0px;但它仍然显示空白。关于从右向左滚动时如何删除左侧多余的空白有什么建议吗?
代码:
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]);
var options = {
title: 'Company Performance',
hAxis: {title: 'Year', titleTextStyle: {color: 'red'}},
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="margin-left:0;white-space: nowrap;overflow-x:auto;overflow-y:hidden;direction:rtl;left:0;top:0;height: 500px;"></div>
</body>
</html>
PS:当我删除direction:rtl
时没有显示额外的空白,但根据我的要求,我需要使用它来使水平滚动条从右向左滚动。
最佳答案
其中一个 div 有:
div {
left: -1000px
}
它可以通过其 aria-label
进行识别和定位:
div[aria-label="A tabular representation of the data in the chart."] {
left: 0 !important;
}
关于javascript - 从右向左滚动时无法删除左侧的空白区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46119605/