我正在使用 Google 图表。定位让我望而却步。我没有在文档中找到那部分。我只想在 div 中创建一个 Google 图表,左上角位于 div 中的 (x, y) 中。帮助控制尺寸的加分。
<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]
]);
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="width: 900px; height: 500px;"></div>
</body>
</html>
如果我使用像 Firebug 这样的工具查看“运行时”中的 html,我会看到:
rect x="161" y="96" width="579" height="309"
但我没有选择任何这些值。
最佳答案
例如,要将图表定位在 DIV 中的 (0,0) 处,请添加图表选项:
var options = {
...,
chartArea:{left:0,top:0,width:"50%",height:"50%"}
}
并根据需要调整宽度和高度;完整的选项是 here .
关于javascript - 如何在网页中定位 Google 图表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12253866/