var chartjson = {
type: 'line',
data: {
labels: [],
datasets: [{
data: [],
lineTension: 0,
backgroundColor: 'transparent',
borderColor: '#007bff',
borderWidth: 1,
pointBackgroundColor: '#007bff'
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: false
}
}]
},
legend: {
display: false,
}
}
};
var step = 1;
if (data.num < 10)
step = parseInt(data.num / 10);
for (var i = 1; i < data.num + 1; i = i + step) {
chartjson.data.labels.push(i);
chartjson.data.datasets[0].data.push(data.dataList[i - 1].temperature);
}
setChart(chartjson);
sessionStorage.chartjson = JSON.stringify(chartjson);
没有哈瓦循环。 JSON chartjson是直接定义的,并且不引用任何变量。我找不到任何圆形结构。 “数据”是这样的JSON对象:
{
"num": 100,
"dataList": [
{
"temperature": 33.1,
"g1": 1.21,
"g2": 0.11,
"g3": 7.7,
"time": "2018-08-03 08:30:33"
},
{
"temperature": 33.2,
"g1": 1.11,
"g2": 0.21,
"g3": 7.7,
"time": "2018-08-03 08:31:19"
},
{
"temperature": 33.3,
"g1": 1.4,
"g2": 0.01,
"g3": 7.6,
"time": "2018-08-03 08:31:42"
},
{
"temperature": 33.4,
"g1": 1.41,
"g2": 0.01,
"g3": 7.7,
"time": "2018-08-03 08:32:06"
}
]
}
我收到错误消息:
Uncaught TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
答案 0 :(得分:0)
是的,是的,setChart函数引用chartjson并将其更改,并使其变为圆形结构。我只是更改“ setChart(chartjson)”和“ sessionStorage.chartjson = JSON.stringify(chartjson);”的命令。它成为正确的。谢谢。