-1
我想用c3.js使用PUBNUB javascript SDK創建圖表。問題是,當我嘗試創建圖表時,它不會讀取json數據,我得到錯誤Uncaught TypeError:無法讀取未定義的屬性「輸出」。閱讀json時出錯Uncaught TypeError:無法讀取未定義的屬性'輸出'
完整的數據是(我派通過Python數據)
m = {
"devices": [
{
"Name": "bdev0",
"output": {
"IO_Operations": 0,
"Bytes_Read": 0,
"Bytes_Written": 0
}
},
{
"Name": "bdev1",
"output": {
"IO_Operations": 0,
"Bytes_Read": 0,
"Bytes_Written": 0
}
}
]
}
而JavaScript是
eon.chart({
pubnub : pubnub,
history : false,
channel : 'chanel',
flow : true,
generate : {
bindto : '#chart_1',
size: {
height: 180,
width: 500
},
data : {
x : 'x',
labels : true
},
axis : {
x : {
type : 'timeseries',
tick : {
format : '%H:%M:%S'
},
zoom: {
enabled: true
}
}
}
},
transform : function(m) {
return { columns : [
['x', new Date().getTime()],
['Bytes Written', m.devices[i].output.Bytes_Read],
['Bytes Read', m.devices[i].output.Bytes_Written]
] };
}
});
使用[i]意味着它會遍歷數組中的所有元素,當我嘗試在簡單的JavaScript中使用它時,它爲什麼會這樣呢?例如看到這個jsfiddle https://jsfiddle.net/umLwwq2a/ – Imo
@Imo正如我所說,你需要**定義'我'**。你在小提琴中的代碼完全是這樣,所以它的工作原理。你上面發佈的代碼**沒有定義'我'**,所以*當然*它不起作用。嘗試從JSFiddle中取出(var i'部分),看看它的工作情況。 – meagar