为google.visualization.DataTable设置列宽 [英] Set column width for google.visualization.DataTable

查看:137
本文介绍了为google.visualization.DataTable设置列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变google.visualization.DataTable中列的宽度,但是我不知道该怎么做。

Fiddler: https://jsfiddle.net/dgbh6sL0/1/



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


  • '名称'列的宽度应该为300px;
  • '全职员工'列宽应为100px;
  • $

    $ b

    任何建议/帮助表示感谢。 p>

    根据建议,以下是应用的解决方案: https: //jsfiddle.net/dgbh6sL0/2/

    解决方案

    您可以这样做:

      data.setProperty(0,0,'style','width:300px'); 

    另外,您需要在draw中使用allowHTML,如:

      table.draw(data,{showRowNumber:true,width:'100%',height:'100%',allowHtml:true}); 


    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

    <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>
    

    JS

    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%'});
      }
    

    Expectation

    • 'Name' column width should be 300px;
    • 'Full Time Employee' column width should be 100px;

    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:

    data.setProperty(0, 0, 'style', 'width:300px');
    

    Also, you need to "allowHTML" in "draw" like:

    table.draw(data, {showRowNumber: true, width: '100%', height: '100%',allowHtml: true});
    

    这篇关于为google.visualization.DataTable设置列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆