Это мой дом. html где я хочу увидеть свою диаграмму и иметь тег сценария. Я установил CDN в базу. html в голове и просто с помощью расширяет в доме. html
{% extends 'base.html' %}
{% block head %}
<title>Home</title>
{% endblock %}
{% block body %}
<hr>
<h2>Home Page</h2>
<canvas id="myChart" width="600" height="400"></canvas>
<hr>
<script src="/static/charts/profit_ot.js" type='text/javascript'></script>
<hr>
<hr>
{% endblock %}
Это js графика, значения которого поступают из моего маршрута.
// Global parameters:
// do not resize the chart canvas when its container does (keep at 600x400px)
Chart.defaults.global.responsive = false;
// define the chart data
var chartData = {
labels : [{% for item in labels %}
"{{item}}",
{% endfor %}],
datasets : [{
label: '{{ legend }}',
fill: true,
lineTension: 0.1,
backgroundColor: "rgba(75,192,192,0.4)",
borderColor: "rgba(75,192,192,1)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#fff",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(75,192,192,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data : [{% for item in values %}
{{item}},
{% endfor %}],
spanGaps: false
}]
}
// get chart canvas
var ctx = document.getElementById("myChart").getContext("2d");
// create the chart using the chart canvas
var myChart = new Chart(ctx, {
type: 'line',
data: chartData,
});
Это прекрасно работает, когда я не делаю файл отдельно, то есть если мой скрипт не имеет sr c, а весь код profit_ot. js in домой. html сам.