[英]“Display:none” does not work if i want to click on a button to let a graph appear or disappear
让图表出现和消失是行不通的。 当我切换时,标签和轴 al 出现在完全相同的位置。 有人能帮我吗? 我认为这与文章(id为“chart”)和canvas(id="cvs")有关。 这是我保存为 HTML 文件的整个代码。
<!DOCTYPE html>
<html lang="en">
<head>
<title> Budget </title>
<meta charset="utf-8">
<script src="RGraph.common.core.js"></script>
<script src="RGraph.common.dynamic.js"></script>
<script src="RGraph.bar.js"></script>
<style>
#click
{
position: absolute;
left: 125px;
top: 350px;
}
</style>
</head>
<body>
<header></header>
<p id="click" onclick="showChart()">Show</p>
<article id="chart" style="display:none">
<h2> TEST </h2>
<canvas id="cvs" width="800" height="300"></canvas>
</article>
</body>
</html>
在我的功能 showChart 中,我参考了 HTML 代码中的文章和 canvas,但它似乎不适用于轴和标签。 轴和标签都出现在左上角完全相同的位置。 我试图用 div 或 section 替换 canvas 但它不起作用。 此外 style="display:none" 似乎也仅适用于图形本身,而不适用于轴、标签和标题。
<script>
bar = new RGraph.Bar
(
{
id: 'cvs',
data: [36.55, 40.4, 40.4, 52],
options:
{
xaxisLabels: ['1','2','3','4'],
title: "Scales",
adjustable: true,
marginLeft: 50,
yaxisScaleMax: 100,
labelsAbove: true,
}
}
)
.draw()
function showChart()
{
var x = document.getElementById("chart");
if (x.style.display === "none")
{
x.style.display = "block";
}
else
{
x.style.display = "none";
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.