ChartJS脚本未显示

时间:2019-07-12 08:34:06

标签: javascript twig chart.js

我正在尝试从外部JS文件向我的Twig视图添加ChartJS脚本:

{% extends 'base.html.twig' %}
{% block title %}Stats Générales{% endblock %}
{% block bodyStats %}
    <div id="preloader">
        <div class="loader"></div>
    </div>
    {{ form(form) }}
    {% if joueurStats is defined %}
        <canvas id="scoreLine" width="50" height="50"></canvas>    
    {% endif %}
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.js" ></script>           
    <script type="text/javascript" src="/js/chartjs-plugin-colorschemes.js"></script>
    <script src="{{ asset('/js/graphs.js') }}"></script>
    <script>

这是JS脚本:

var ctx = document.getElementById("scoreLine");
ctx.height = 500;
var myLineChart = new Chart(ctx, {
    type: 'line',
    data: {
        labels : "{{joueurStats| chart | raw}}",
        datasets : [{
            label : ["Average"],
            data : "{{joueurStats | score | raw}}",
            backgroundColor: '#ABCDFF',              
            borderColor: '#3752FF',
            borderWidth: 1,
        }]
    },
    options: {
        tooltips: {
            mode: 'nearest'
        },
        scales: {
            xAxes: [{

                ticks: {
                    autoSkip: false,
                    maxRotation: 90,
                    minRotation: 90
                }
            }]
        }
    }
});

graph.js文件已正确加载,但未显示图形。我收到此错误消息:

  

Chart.js:4812未捕获的TypeError:调用了Object.defineProperty   非客体       在Function.defineProperty()       在listenArrayEvents(Chart.js:4812)       在ChartElement.buildOrUpdateElements(Chart.js:4992)       在图表上。 (Chart.js:4231)       在Object.each(Chart.js:9952)       在Chart.update(Chart.js:4230)       在Chart.construct(Chart.js:3962)       在新图表上(Chart.js:6264)       在graphs.js:3

我对javascript不太满意,显然我在其中出错了。

0 个答案:

没有答案