我正在使用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.