ChartJS shows up and disappears

南楼画角 提交于 2019-12-25 00:26:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!