为什么图表.js在引导块中不显示结果



chart.html不显示条形图,它应该是https://www.chartjs.org/docs/latest/getting-started/

chart.html

{% extends "base.html" %}
{% block js %}
<div>
<canvas id="myChart"></canvas>
</div>
<script src="../static/js/try.js"></script>
{% endblock %}

try.js

import 'https://cdn.jsdelivr.net/npm/chart.js';
const ctx = document.getElementById('myChart');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});

importtry.js中失败。

解决方案是在chart.html中重新定位import

chart.html:中

{% extends "base.html" %}
{% block js %}
<div>
<canvas id="myChart"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="../static/js/try.js"></script>
{% endblock %}

我试过了,效果很好。

相关内容

  • 没有找到相关文章

最新更新