如何确定dc.js中的尺寸和组? [英] How to decide dimensions and groups in dc.js?
问题描述
我是dc.js
的新手,在确定尺寸和组时遇到问题.我有这样的数据
I am new to dc.js
and facing issues in deciding dimensions and groups. I have data like this
this.data = [
{Type:'Type1', Day:1, Count: 20},
{Type:'Type2', Day:1, Count: 10},
{Type:'Type1', Day:2, Count: 30},
{Type:'Type2', Day:2, Count: 10}
]
我必须显示两个折线图的组合图,一个折线图用于类型1,另一个折线用于类型2.我的x轴将为Day.所以我的尺寸之一将是天
I have to show a composite chart of two linecharts one for type Type1 and other for Type2. My x-axis will be Day. So one of my dimensions will be Day
var ndx = crossfilter(this.data);
var dayDim = ndx.dimension(function(d) { return d.Day; })
如何进行分组?如果我在Count上执行此操作,则会显示特定日期的总计数,而这是我所不希望的.
How the grouping will be done? If I do it on Count, the total count of a particular Day shows up which I don't want.
推荐答案
您的问题尚不完全清楚,但是听起来您想同时按Type
和Day
Your question isn't entirely clear, but it sounds like you want to group by both Type
and Day
一种方法是使用组合键:
One way to do it is to use composite keys:
var typeDayDimension = ndx.dimension(function(d) {return [d.Type, d.Day]; }),
typeDayGroup = typeDayDimension.group().reduceSum(function(d) { return d.Count; });
然后,您可以使用序列图在合成图内生成两个折线图.
Then you could use the series chart to generate two line charts inside a composite chart.
var chart = dc.seriesChart("#test");
chart
.width(768)
.height(480)
.chart(function(c) { return dc.lineChart(c); })
// ...
.dimension(typeDayDimension)
.group(typeDayGroup)
.seriesAccessor(function(d) {return d.key[0];})
.keyAccessor(function(d) {return +d.key[1];}) // convert to number
// ...
有关更多详细信息,请参见系列图表示例.
See the series chart example for more details.
这篇关于如何确定dc.js中的尺寸和组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!