【发布时间】:2016-02-13 15:13:15
【问题描述】:
如何基于此 JSON 格式在 C3(或 D3)图中显示数据:
[{"Type":"Dog","Number":13},{"Type":"Cat","Number":21}]
这是带有来自 JSON 数据的角度控制器,问题在于定义 keys 属性。我对将类型与数字合并有点困惑。请看一下plunker
angular.module('c3example', [])
.controller('ExampleCtrl', function($scope){
d3.json('/chartData.json', function(err, data){
if(err){ throw err; }
$scope.data = data;
$scope.chart_types = c3.generate({
bindto: d3.select('#chart'),
size: {
weight: 640,
height: 480
},
data: {
json: $scope.data,
keys: {
value: ['Dog', 'Cat'],
},
type: 'bar'
},
bar: {
width: {
ratio: 0.5 //
}
}
});
});
})
在 HTML 中绑定:
<!DOCTYPE html>
<html>
<body ng-app="c3example" ng-controller="ExampleCtrl">
<div class="row">
<div id="chart" build-chart></div>
</div>
</body>
</html>
【问题讨论】:
-
不幸的是 plunker 甚至没有加载 json
-
谢谢塔马斯,我已经更新了。
标签: javascript angularjs json d3.js c3.js