the reason this is happening is that your canvas's parent, .library is hidden at the time of initialization, which sets the canvas height and width to 0. see this answer canvas height/width 0

the solution is to first initialize the canvas and then hide the .library div. see code below:

$(function() {
  $("#hide").on("click", () => {

  var linedata = {
    labels: ["january", "february", "march", "april", "may", "june"],
    datasets: [{
      fillcolor: "rgba(172,194,132,0.4)",
      strokecolor: "#acc26d",
      pointcolor: "#fff",
      pointstrokecolor: "#9db86d",
      data: [186, 156, 251, 144, 305, 236]
  var line = document.getelementbyid('line').getcontext('2d');
  new chart(line).line(linedata);

<script src=""></script>
<script src=''></script>

<button id="hide">hide</button>
<div class="library" id="chart">

  <canvas id="line" width="600" height="400"></canvas>


Related Query

More Query from same tag