Possible to use dc as "basic chart" without crossfilter?

528 views
Skip to first unread message

Xavier Dutoit

unread,
Dec 6, 2013, 3:57:11 AM12/6/13
to dc-js-us...@googlegroups.com
Hi,

I'm using dc for multi-dimensional reports and love it. From time to
time, I have a simple "draw a pie" need.

going through the crossfilter way feels a bit heavyweight, but I'd
like to avoid switching to a different d3 pie, mostly to keep the same
visual style.

I remember having seen a mention of dc handling directly row data in
2.0, but can't find the reference or documentation.

Is there a way to draw a pie [{title:"item A",value:40}, {title:"item
B",value:60}] without crossfiltering it?

Jacob Rideout

unread,
Dec 6, 2013, 11:55:51 AM12/6/13
to dc-js-us...@googlegroups.com
Most the charts now support setting `.data`. By default this calls `group.all()`, but you can have it return arbitrary data instead. 

For example, this will render the chart from http://nickqizhu.github.io/dc.js/examples/pie.html without crossfilter.

  chart
    .width(768)
    .height(480)
    .slicesCap(4)
    .innerRadius(100)
    .dimension({}).group({})
    .data(function() {
      return [{"key":"run-17","value":75480},{"key":"run-18","value":77040},{"key":"run-19","value":80180},{"key":"run-20","value":85000},{"others":["run-1","run-10","run-11","run-12","run-13","run-14","run-15","run-16","run-2","run-3","run-4","run-5","run-6","run-7","run-8","run-9"],"key":"Others","value":576150}];
      })
    .legend(dc.legend());

Xavier Dutoit

unread,
Dec 6, 2013, 5:31:25 PM12/6/13
to Jacob Rideout, dc-js-us...@googlegroups.com
Awesome!

Works great thanks.
Reply all
Reply to author
Forward
0 new messages