返回不适用于HTML

时间:2017-01-05 12:36:02

标签: javascript html canvasjs

您好我正在开发饼图和圆环图。因此,就像加载页面饼图将在圆环图中打开一样。通过点击圆环图,它将打开另一个圆环图。并且通过点击这将进入初始状态有一个链接。

这是我的小提琴 - 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>

现在基本上我的问题非常小。我需要我的后退链接位于页面的左上角位置。所以,如果我在图表上方移动链接的div标签,则链接不起作用,但如果我在它工作之后放置它。所以,我的问题为什么它不起作用,我该怎么做才能使它工作。

如果这是一件非常简单的事,请原谅我。

1 个答案:

答案 0 :(得分:1)

z-index问题。 div-&gt;图表位于div-&gt;链接上,您无法点击
position:relative;z-index:100放入div-&gt;链接