我已经在我的观点中宣布了这一点。当我运行我的django应用程序时,它显示一个空白页但是当我按下ctrl + u时,我可以看到我的y值正确呈现但我的x值呈现为空白。我的目标是在x当前时间。
<script type="text/javascript">
$(function () {
$(document).ready(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});
$('#container').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function () {
var x = (new Date()).getTime(), // current time
y = {{ t }} ;
series.addPoint([x, y], true, true);
}, 3000);
}
}
},
title: {
text: 'Live temperature sensor values'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Sensor data',
data: (function () {
// generate an array of sensor data
var data = [],
time = (new Date()).getTime(),
{% for item in t %}
data.push({
{% for i in 12 %}
{% if t.i == item %}
x: time + {{ i }} * 3000,
{% endif %}
{% endfor %}
y: {{ item }}
});
{% endfor %}
return data;
}())
}]
});
});
});
</script>
ctrl + u
<script type="text/javascript">
$(function () {
$(document).ready(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});
$('#container').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function () {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function () {
var x = (new Date()).getTime(), // current time
y = ['23.125', '23.125', '23.125', '23.125', '23.125', '23.125', '23.125', '23.125', '23.125', '23.187', '23.125', '23.187'] ;
series.addPoint([x, y], true, true);
}, 3000);
}
}
},
title: {
text: 'Live temperature sensor values'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Sensor data',
data: (function () {
// generate an array of sensor data
var data = [],
time = (new Date()).getTime(),
data.push({
x: time + 1 * 3000,
y: 23.125
});
data.push({
x: time + 2 * 3000,
y: 23.125
});
data.push({
x: time + 3 * 3000,
y: 23.125
});
data.push({
x: time + 4 * 3000,
y: 23.125
});
data.push({
x: time + 5 * 3000,
y: 23.125
});
data.push({
x: time + 6 * 3000,
y: 23.125
});
data.push({
x: time + 7 * 3000,
y: 23.125
});
data.push({
x: time + 8 * 3000,
y: 23.125
});
data.push({
x: time + 9 * 3000,
y: 23.125
});
data.push({
x: time + 10 * 3000,
y: 23.187
});
data.push({
x: time + 11 * 3000,
y: 23.125
});
data.push({
x: time + 12 * 3000,
y: 23.187
});
return data;
}())
}]
});
});
});
</script>
&#13;
答案 0 :(得分:0)
我将猜测你想要做什么...你试图迭代一个列表,当你发现一个等于你要显示x值的项的值时,它看起来相当于只添加item
作为x
{% for item in t %}
data.push({ x: time + {{ item }} * 3000,
当项目处于第二位置时时间+ 1 * 1000
您只需使用forloop.counter
data.push({ x: time + {{ forloop.counter }} * 3000,
至于为什么你不能做其他两件事的参考:
迭代范围 - Numeric for loop in Django templates
通过变量访问数组元素 - How can I use a variable as index in django template?