它的nv d3条形图程序的源程序现在我把条形图数据的硬编码分开了,即data.json,它现在不显示图表。在NV D3水平条形图中如何使用Json作为数据?
<script>
d3.json("Data.json", function (data) {
var chart;
nv.addGraph(function() {
chart = nv.models.multiBarHorizontalChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.margin({top: 30, right: 20, bottom: 50, left: 175})
.showValues(true)
.tooltips(false)
.showControls(false);
chart.yAxis
.tickFormat(d3.format(',.2f'));
d3.select('#chart1 svg')
.datum(data)
.transition().duration(500)
.call(chart);
nv.utils.windowResize(chart.update);
chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e));
});
return chart;
});
});
</script>
下面是我从源分离data.json它不工作
[
{
"label" : "Group A" ,
"value" : -1.8746444827653
} ,
{
"label" : "Group B" ,
"value" : -8.0961543492239
} ,
{
"label" : "Group C" ,
"value" : -0.57072943117674
} ,
{
"label" : "Group D" ,
"value" : -2.4174010336624
} ,
{
"label" : "Group E" ,
"value" : -0.72009071426284
} ,
{
"label" : "Group F" ,
"value" : -0.77154485523777
} ,
{
"label" : "Group G" ,
"value" : -0.90152097798131
} ,
{
"label" : "Group H" ,
"value" : -0.91445417330854
} ,
{
"label" : "Group I" ,
"value" : -0.055746319141851
}
]
请大家帮我出了什么问题,当我分开JSON
我已经改变仍无法正常工作.. – Purushoth 2013-02-23 17:00:16
第二个错误是由kapep提到的:你需要坚持,即使你有一个系列相同的格式,否则所有的功能,将需要在图表级别处理这些数据将不起作用(他们将没有数据加载,例如...) – paxRoman 2013-02-23 19:15:22