JS (document.getElementById("example").textContent) 不显示 var 中的内容
JS (document.getElementById("example").textContent) doesn't show content in var
当我尝试使用 id load2 的内容显示实时图表时
它没有 return 任何东西,但当我将 textContent 放入控制台日志时
它确实显示数字我做错了什么?
$(function () {
$(document).ready(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});
Highcharts.chart('container', {
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
var y = (document.getElementById("load2").textContent);
console.log(document.getElementById("load2").textContent);
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
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: 'Random data',
data: (function () {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -50; i <= 0; i += 1) {
data.push({
x: time + i * 1000,
y: 0
});
}
return data;
}())
}]
});
});
});
此 load2 元素来自 JSON 拉取请求
highcharts 验证 addPoint 中的参数类型并忽略 y,因为它是字符串而不是 int 或 float
使用 parseFloat
或 ParseInt
。
parseFloat(document.getElementById("load2").textContent);
当我尝试使用 id load2 的内容显示实时图表时 它没有 return 任何东西,但当我将 textContent 放入控制台日志时 它确实显示数字我做错了什么?
$(function () {
$(document).ready(function () {
Highcharts.setOptions({
global: {
useUTC: false
}
});
Highcharts.chart('container', {
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
var y = (document.getElementById("load2").textContent);
console.log(document.getElementById("load2").textContent);
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
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: 'Random data',
data: (function () {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -50; i <= 0; i += 1) {
data.push({
x: time + i * 1000,
y: 0
});
}
return data;
}())
}]
});
});
});
此 load2 元素来自 JSON 拉取请求
highcharts 验证 addPoint 中的参数类型并忽略 y,因为它是字符串而不是 int 或 float
使用 parseFloat
或 ParseInt
。
parseFloat(document.getElementById("load2").textContent);