问题
So I am using ChartJS alongside a Bootstrap 4 and Laravel Project. The code is fine(see below). Every time I refresh the page, the chart shows up for like a millisecond and goes away.
<div class="col-md-6">
<div>
<canvas id="pie-chart" style="width:100%;"></canvas>
<!-- Pie Chart -->
<script>
new Chart(document.getElementById("pie-chart"), {
type: 'pie',
data: {
labels: ["College Project", "Mind Map", "Designers Club"],
datasets: [{
label: "Population (millions)",
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f"],
data: [2478,5267,734]
}]
},
options: {
title: {
display: true,
text: 'Tasks Division'
}
}
});
</script>
</div>
</div>
回答1:
I had the same issue. The problem was from the defer loading of the app.js in the layout.
<script src="{{ asset('js/app.js') }}" defer></script>
It was loading after my and a Vue instanciation was created. I think this is why the chart was disappearing.
I hope it helps someone.
来源:https://stackoverflow.com/questions/53884674/chartjs-shows-up-and-disappears