gpt4 book ai didi

javascript - 点击后显示折线图

转载 作者:行者123 更新时间:2023-11-28 08:14:55 26 4
gpt4 key购买 nike

我在此链接中使用来自谷歌的可视化:折线图 https://google-developers.appspot.com/chart/interactive/docs/gallery/linechart

这是代码

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

var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>

我的问题是当我使用此代码时总是显示在页面上我想在单击按钮后显示折线图

最佳答案

我猜你想做的是这样的:

演示: http://jsfiddle.net/K5aMG/3/

JavaScript:

    function showChart(){
document.getElementById('mychart').style.display='block';
}

HTML:

<div id="mychart" style="display:none;">     
<div id="chart_div" style="width:900px; height: 500px;"></div>
</div>
<div onclick="showChart();">click here to show a chart </div>

希望这有帮助。

关于javascript - 点击后显示折线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23717556/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com