如何使用 json 数据创建 angular nvd3 多柱状图和堆积图
How to create angular nvd3 multibar and stacked chart using json data
我想使用以下 json 数据创建一个 angular nvd3 多条形图。
json:
[
{
"ccpProducts": "CME",
"color": "red",
"values": [
{
"dates": "2015-07-01 00:00:00.0",
"noOfTrades": 5281
}
]
},
{
"ccpProducts": "LCH",
"color": "#6b486b",
"values": [
{
"dates": "2015-07-01 00:00:00.0",
"noOfTrades": 5281
}
]
}
]
由于 values
是一个对象数组,您不能像现在这样通过它们的索引访问其属性(对象属性未排序):
// d[0] and d[1] are undefined!
x: function(d){ return new d[0]; },
y: function(d){ return d[1]; }
你应该这样做:
x: function(d){ return new d['dates']; },
y: function(d){ return d['numOfTrades']; }
您还可以转换 bar.json
中数据的格式。
我想使用以下 json 数据创建一个 angular nvd3 多条形图。
json:
[
{
"ccpProducts": "CME",
"color": "red",
"values": [
{
"dates": "2015-07-01 00:00:00.0",
"noOfTrades": 5281
}
]
},
{
"ccpProducts": "LCH",
"color": "#6b486b",
"values": [
{
"dates": "2015-07-01 00:00:00.0",
"noOfTrades": 5281
}
]
}
]
由于 values
是一个对象数组,您不能像现在这样通过它们的索引访问其属性(对象属性未排序):
// d[0] and d[1] are undefined!
x: function(d){ return new d[0]; },
y: function(d){ return d[1]; }
你应该这样做:
x: function(d){ return new d['dates']; },
y: function(d){ return d['numOfTrades']; }
您还可以转换 bar.json
中数据的格式。