[英]Google Pie Chart with Width of Parent
I'm using bootstrap3
, looked at this documentation assuming I have something like below: 我正在使用bootstrap3
,假设我有以下内容,请查看此文档 :
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-4 col-xs-4">
<div class="well">
<header>Genel İstatistik</header>
<content id="general"></content>
<footer>Footer</footer>
</div>
</div>
I want my chart to have width of my div and auto resize height by width, in this case, width is defined by col-*-4
rule. 我希望图表具有div的宽度并按宽度自动调整高度,在这种情况下,宽度由col-*-4
规则定义。 How to make width 100% to parent at options
? 如何使宽度为父options
100%?
Okay, so it seems there is no built-in way to define width of Google Pie Chart responsively. 好的,因此似乎没有内置方法可以快速定义Google饼图的宽度。 However, I figured a way out, so there it is. 但是,我想出了一条出路,就是这样。 According to the documentation on Google, passing an example options
variable to .draw()
function will define the size, the options
as below: 根据Google上的文档,将示例options
变量传递给.draw()
函数将定义大小, options
如下:
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};
So, all I have to do is get the width of document
and do some simple maths, like: 因此,我要做的就是获取document
的宽度并做一些简单的数学运算,例如:
var width = $(document).width();
var options = {'title':'How Much Pizza I Ate Last Night',
'width':width/3,
'height':300};
width/3
is fine for me, but you might want to take the parent's width then apply. width/3
对我来说很好,但是您可能想要采用父母的宽度然后申请。 In this case, you might want to look at this answer . 在这种情况下,您可能需要查看此答案 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.