返回在 HTML 中不起作用

Back is not working in HTML

您好,我正在开发饼图和圆环图。所以,就像加载页面时饼图将在圆环图中打开一样。通过单击甜甜圈图,它将打开另一个甜甜圈图。并且有一个link,点击它进入初始状态。

这是我的 fiddle - Fiddle link

无论如何我在这里发布我的代码-

<!DOCTYPE HTML>
<html>
<head>
<script src="http://canvasjs.com/assets/script/canvasjs.min.js"></script> 
<!-- <link type='text/css' rel="stylesheet" href='style.css' /> -->
<style>
#chartContainerpie{
  position: absolute;
  top: 130px;
  left: 0px;
}
#chartContainer{
  position: absolute;
  top: 0px;
  left: 0px;
}
#link {
visibility : hidden;
top : 0px;
left : 0px;
}
</style>
<script type="text/javascript">

window.onload = function () {
    var chart = new CanvasJS.Chart("chartContainer", {
  title: {
    text: "My First Chart in CanvasJS"
  },
  backgroundColor: "transparent",
  data: [{
    click: function(e){
       anotherchart();
   },
    // Change type to "doughnut", "line", "splineArea", etc.
    type: "doughnut",
    dataPoints: [{
      label: "apple",
      y: 10
    }, {
      label: "orange",
      y: 15
    }, {
      label: "banana",
      y: 25
    }, {
      label: "mango",
      y: 30
    }, {
      label: "grape",
      y: 28
    }]
  }]
});
chart.render();
var chart = new CanvasJS.Chart("chartContainerpie", {
    backgroundColor: "transparent",
  data: [{
    // Change type to "doughnut", "line", "splineArea", etc.
    indexLabelPlacement: "inside",
    indexLabelFontColor: "white",
    indexLabelFontSize: "14px",
    type: "pie",
    dataPoints: [{
      label: "apple",
      y: 10
    }, {
      label: "orange",
      y: 15
    }, {
      label: "banana",
      y: 25
    }, {
      label: "mango",
      y: 30
    }, {
      label: "grape",
      y: 28
    }]
  }]
});
chart.render();
}
function anotherchart () {
 document.getElementById("chartContainerpie").innerHTML = "";
  document.getElementById("chartContainer").innerHTML = "";
  document.getElementById("link").style.visibility = "visible";
 // alert(  e.dataSeries.type+ ", dataPoint { x:" + e.dataPoint.x + ", y: "+ e.dataPoint.y + " }" );
   var chart = new CanvasJS.Chart("chartContainernew", {
    backgroundColor: "transparent",
  data: [{
    // Change type to "doughnut", "line", "splineArea", etc.
    indexLabelPlacement: "inside",
    indexLabelFontColor: "white",
    indexLabelFontSize: "14px",
    type: "doughnut",
    dataPoints: [{
      label: "apple",
      y: 10
    }, {
      label: "orange",
      y: 15
    }, {
      label: "banana",
      y: 25
    }, {
      label: "mango",
      y: 30
    }, {
      label: "grape",
      y: 28
    }]
  }]
});
chart.render();
}

</script>
</head>
<body>
<div>
  <div id="chartContainerpie" style="height: 188px; width: 100%;"></div>
  <div id="chartContainer" style="height: 400px; width: 100%; "></div>
</div>
<div>
  <div id="chartContainernew" style="height: 400px; width: 100%; "></div>
  <a id="link" href="">Back</a>
</div>
</body>
</html>

现在基本上我的问题很小了。我需要我的后退 link 位于页面的左上角。因此,如果我将 link 的 div 标记移动到图表上方,link 将不起作用,但如果我将其放在它起作用之后。所以,我的问题是为什么它不起作用,我该怎么做才能让它起作用。

很简单的事情还请见谅。

是一个z-index问题。 div->图表位于 div->link 上方,您 无法单击它
position:relative;z-index:100 到 div->link