问题描述
我想改变google.visualization.DataTable中列的宽度,但是我不知道该怎么做。
Fiddler:
HTML
< script type =text / javascript SRC =https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1.1','packages':['table']} ]}>< /脚本>
< div id =table_div>< / div>
JS
google.setOnLoadCallback(drawTable);
函数drawTable(){
var data = new google.visualization.DataTable();
data.addColumn('string','Name');
data.addColumn('number','Salary');
data.addColumn('布尔','全职员工');
data.addRows([
['Mike',{v:10000,f:'$ 10,000'},true],
['Jim',{v:8000,f:' $ 8,000'},false],
['Alice',{v:12500,f:'$ 12,500'},true],
['Bob',{v:7000,f:'$ 7000' },true]
]);
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data,{showRowNumber:true,width:'100%',height:'100%'});
}
期望 $ b 任何建议/帮助表示感谢。 p> 根据建议,以下是应用的解决方案: 您可以这样做: 另外,您需要在draw中使用allowHTML,如: I want to change the width of the columns in google.visualization.DataTable but, I am not sure how to do it. Fiddler: https://jsfiddle.net/dgbh6sL0/1/ HTML JS Expectation Any suggestion / help is appreciated. EDIT Based on the suggestion, here is the applied solution: https://jsfiddle.net/dgbh6sL0/2/ You can do this like: Also, you need to "allowHTML" in "draw" like: 这篇关于为google.visualization.DataTable设置列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
$ b
data.setProperty(0,0,'style','width:300px');
table.draw(data,{showRowNumber:true,width:'100%',height:'100%',allowHtml:true});
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1.1','packages':['table']}]}"></script>
<div id="table_div"></div>
google.setOnLoadCallback(drawTable);
function drawTable() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('number', 'Salary');
data.addColumn('boolean', 'Full Time Employee');
data.addRows([
['Mike', {v: 10000, f: '$10,000'}, true],
['Jim', {v:8000, f: '$8,000'}, false],
['Alice', {v: 12500, f: '$12,500'}, true],
['Bob', {v: 7000, f: '$7,000'}, true]
]);
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true, width: '100%', height: '100%'});
}
data.setProperty(0, 0, 'style', 'width:300px');
table.draw(data, {showRowNumber: true, width: '100%', height: '100%',allowHtml: true});