我有点困惑,这就是我的烧瓶和JS的样子,wtime在图中正确显示,但是我无法让{{wtech}}用作JS中的烧瓶值。在这上面花了我相当长的时间。我宁愿使用Flask变量,也不必求助于JSON,因为它更容易编写代码,并且耗时更少。
对于{{wtime}}(对于数据)来说,它工作得很好,但对标签来说,{{wtech}}则无法使用
烧瓶:
wtech = ['Tech1','Tech2']
wtime = [3,4]
res = make_response(render_template("timeman.html", wtech = wtech,
wtime = wtime))
JavaScript:
<script>
var cty = document.getElementById("chartBig2").getContext("2d");
var data = {
labels: ['Tech1','Tech2'],
datasets: [{
label: "Data",
fill: true,
backgroundColor: ['#1d1d2e', '#2d2f54'],
borderColor: '#d048b6',
borderWidth: 2,
data: {{wtime}}, }]};
var myDough = new Chart(cty, {type: 'doughnut', data: data, options: gradientDoughOptionsConfiguration});
</script>
答案 0 :(得分:0)
非常感谢Joe,我找到了另外两篇文章,但是我一直在寻找答案的那篇文章是关于sopython-> {{value | tojson}}的文章。
那太完美了,正是我想要的。