JSFiddle - React, Tailwind, and code Playground

by Aditya Shrivastava

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.min.js"></script>
<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>

CSS

#chartContainerpie{
  position: absolute;
  top: 130px;
  left: 0px;
}
#chartContainer{
  position: absolute;
  top: 0px;
  left: 0px;
}
#link {
visibility : hidden;
top : 0px;
left : 0px;
position:relative;
z-index:100;
}

JavaScript

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();