【发布时间】:2020-09-25 21:47:05
【问题描述】:
我将更新 d3 图表脚本中的数据变量,而不使用从 view.py 发送的变量 ajax 刷新屏幕。怎么更新呢,d3图表中的变量是{{totalSalesGraph|safe}}
htmlFile.html
<html>
<div class="graphTotalSale">
<div id="graphSale"></div>
</div>
<script>
setInterval(function() {
$.ajax({
type: "GET",
url: "{% url 'updateData' %}"
})
.done(function(response) {
// how to update {{totalSalesGraph}} variable in d3 chart. (new value is response.totalSalesGraph)
});
}, 5000)
</script>
<script>
var margin = {top: 10, right: 30, bottom: 30, left: 60},
width = 550
height = 120
var svg = d3.select("#graphSale")
...
//Read the data
var data = {{totalSalesGraph|safe}}
...
</script>
<html>
【问题讨论】:
标签: javascript html django ajax d3.js