0

我无法在页面上使用 Chart.js 显示图表。我尝试了多个示例,但似乎无法显示图表,否则页面为空。这个当前版本我为 Chartjs 的 javascript 创建了一个单独的文件。目前的数据只是来自一个例子。

page.html

<body>
    <p>hello</p>

    <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3"></script>
    <script src="../../../assets/winCharts/azbacks.js"> </script>

    <canvas id="winGraph" width="800" height="800"></canvas>
</body>

/assets/azbacks.js

var data = {
    labels: ["January", "February", "March", "April", "May", "June", "July"],
    datasets: [{
      label: "My First dataset",
      fillColor: "rgba(220,220,220,0.2)",
      strokeColor: "rgba(220,220,220,1)",
      pointColor: "rgba(220,220,220,1)",
      pointStrokeColor: "#fff",
      pointHighlightFill: "#fff",
      pointHighlightStroke: "rgba(220,220,220,1)",
      data: [65, 59, 80, 81, 56, 55, 40]
    }, {
      label: "My Second dataset",
      fillColor: "rgba(151,187,205,0.2)",
      strokeColor: "rgba(151,187,205,1)",
      pointColor: "rgba(151,187,205,1)",
      pointStrokeColor: "#fff",
      pointHighlightFill: "#fff",
      pointHighlightStroke: "rgba(151,187,205,1)",
      data: [28, 48, 40, 19, 86, 27, 90]
    }]
  };

var options = {
    animation: false,
    ///Boolean - Whether grid lines are shown across the chart
    scaleShowGridLines: true,
    //Boolean - Whether to show vertical lines (except Y axis)
    scaleShowVerticalLines: true,
    showTooltips: false
};

var ctx = document.getElementById("winGraph").getContext("2d");
var myLineChart = new Chart(ctx, {
    type: 'line',
    data: data,
    options: options
});
4

0 回答 0