Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export dc.js filtered data

I'm using dc.js library to generate graphs and I would like to be able to retrieve the filtered data when filters are applied.

like image 256
Boris Barroso Avatar asked Mar 19 '23 06:03

Boris Barroso


2 Answers

Create another dimension and then call dimension.top(Infinity) on it.

https://github.com/square/crossfilter/wiki/API-Reference#dimension_top

You will need the extra dimension because dimensions do not observe their own filters, only the filters on other dimensions.

Then you can use e.g. d3.csv.format to produce text, if you need to.

https://github.com/mbostock/d3/wiki/CSV#format

like image 89
Gordon Avatar answered Mar 23 '23 00:03

Gordon


In the version 4 of d3.js d3.csv.format doesn't exist, you must use d3.csvFormat instead.

const cf = crossfilter(data);

csvDimension = cf.dimension( x => x );

csvContent = d3.csvFormat(csvDimension.top(Infinity), [field, field2, ...]);

As Gordon said, csvDimension must be a new dimension in order for the filters to be applied.

like image 32
Suriem Avatar answered Mar 22 '23 23:03

Suriem