【发布时间】:2014-07-29 19:13:23
【问题描述】:
我想创建一个基本条形图,其中 x 轴为“类型”,y 轴为唯一计数。我似乎无法在 x 轴上找到类型的示例(甚至在教程中也没有)
我有以下代码:
<div id='dc-bar-chart'></div>
这是数据
var data = [{
date: "2011-11-14T16:17:54Z",
quantity: 2,
total: 190,
tip: 100,
type: "tab"
}, {
date: "2011-11-14T16:20:19Z",
quantity: 2,
total: NaN,
tip: 100,
type: "tab"
}, {
date: "2011-11-14T16:28:54Z",
quantity: 1,
total: 300,
tip: 200,
type: "visa"
}, {
date: "2011-11-14T16:30:43Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T16:48:46Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T16:53:41Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T16:54:06Z",
quantity: 1,
total: NaN,
tip: null,
type: "cash"
}, {
date: "2011-11-14T17:02:03Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T17:07:21Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T17:22:59Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T17:25:45Z",
quantity: 2,
total: 200,
tip: null,
type: "cash"
}, {
date: "2011-11-14T17:29:52Z",
quantity: 1,
total: 200,
tip: 100,
type: "visa"
}];
这是我的代码
ndx = new crossfilter(data)
var XDimension = ndx.dimension(function (d) {return d.type;});
var YDimension = XDimension.group().reduceSum(function (d) {return d.total;});
dc.barChart("#dc-bar-chart")
.width(480).height(150)
.dimension(XDimension)
.group(YDimension)
.centerBar(true)
.gap(56)
});
dc.renderAll();
【问题讨论】:
-
第二个代码块中有一个流浪的
});。是否还有更多正在使用的代码丢失?
标签: javascript d3.js graph dc.js crossfilter