javascript - 谷歌图表点击全屏

标签 javascript jquery google-visualization

有没有办法让 Google 图表在点击时全屏显示?

我已经研究这个好几个小时了

JS-

 $('#chart_div').on('click', function(e) {
     $(this).css({
         width: "100%",
         height: "100%",
         margin: "0",
         border: "none"

     });
 });

CSS -

#chart_div {
    width: 100 px;
    height: 100 px;
    margin: 20 px;
    background - color: red;
    border: 1 px solid black;
}
body, html {
    height: 100 % ;
}

HTML - 您可以根据以下条款自由复制和使用此示例 Apache 许可证 ( http://www.apache.org/licenses/LICENSE-2.0.html )

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>
        Google Visualization API Sample
    </title>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load('visualization', '1', {
            packages: ['corechart']
        });
    </script>
    <script type="text/javascript">
        google.load("visualization", "1", {
            packages: ["corechart"]
        });
        google.setOnLoadCallback(drawChart);

        function drawChart() {
            var data = google.visualization.arrayToDataTable([
                ['Year', 'Sales', 'Expenses'],
                ['November', 1000, 400],
                ['December', 1170, 460],
                ['January', 660, 1120],
                ['February', 690, 1120],
                ['March', 780, 1120],
                ['April', 820, 1120],
                ['May', 660, 1120],
                ['June', 1030, 540]
            ]);

            var options = {
                title: '',
                backgroundColor: 'none',
                legend: {
                    position: 'none'
                },
                hAxis: {
                    title: 'Year',
                    titleTextStyle: {
                        color: 'grey'
                    }
                },
                chartArea: {
                    left: 40,
                    top: 10,
                    width: 900,
                    height: 350
                }
            };

            var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
            chart.draw(data, options);
        }

        $('#chart_div').on('click', function(e) {
            $(this).css({
                width: "100%",
                height: "100%",
                margin: "0",
                border: "none"

            });
        });
    </script>
</head>

<body style="font-family: Arial;border: 0 none;">
    <div id="chart_div"></div>
</body>

</html>
​

http://jsfiddle.net/FbKEL/5/

非常感谢任何帮助。

最佳答案

你不能再调用一次drawChart吗?

$('#chart_div').on('click',function(e){
    $(this).css({
        width:"100%",
        height:"100%",
        margin:"0",
        border:"none"  
    });
    drawChart();
});

参见here

关于javascript - 谷歌图表点击全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14202553/

相关文章:

javascript - 如何使用 JavaScript OOP 在附加的事件处理程序中引用 'real' this?

javascript - 使用 ajax 发出 http 请求以获得基本授权和 cors

jquery json 对象

javascript - 当数据类型混合时从 Google 电子表格访问数据

javascript - 如何使用 xirr 公式的 Javascript 类

javascript - 我可以在创建新的 Web Workers 对象时将参数传递给 .js 函数吗?

jquery - 将日期选择器分配给输入字段数组

javascript - 在 php 中刷新时,变量在上一页的查询字符串中丢失

charts - 如何在 Google Charts 中的图表区域周围绘制边框?

javascript - 为 Google Visualization Table Chart 设置选定行的 css 属性