How to export to CSV


#1

Hi there. Simple question: Is there a way to export to CSV or JSON (or just simple text) the data from a Raw Data Table natively? If not is there a way to get the data stored in it so I can build/export it myself?


#2

Hi there @william. Actually is possible to export data as CSV from the RDT. Right now is only available through the AQL, but we are planning to include it in the UI in the future.

To export to CSV from a Raw Data Table is very easy:

const rdt = cf.getVisualization('rdt-element');

rdt.get('csv')()

Note the extra () at the end, is because get('csv') returns a function. This will automatically download the csv file to your default download folder or it will ask you were to store it depending on your browser.

I hope it helps


#3

Thanks! One last question: Is there an easier way to get the element if I’m in ChartFactor Studio? For now I manually inspect the element and grab it from the div id.


#4

There is a global function in Studio you can use for that: getId("widget name"), where widget name is the title of the widget containing the visualization. You can use it from the developer tools or even from any other widget.


#5

Thanks @gen_dev! Of course. I was editing the Interaction Manager and I saw the getId function being used. I completely missed that.


#6

This is really helpful. I was about to ask the question but I saw the thread.

I have an additional question: Is it possible to do the same from any other visualization? I mean to obtain the data?. The thing is that in more that one occasion we have needed the data from a Bars or a Pie visualization for example.

We’ve sort of worked around it by using Slicers. But we’ve sort of wanted to obtain the data to export it as json or csv as well.


#7

Hi @sandip. You can obtain the data from any visualization in JSON format like this:

const visual = cf.getVisualization('div-id')

visual.get('data')

The format of the JSON object obtained is described here in the documentation.


#8

Just in case, @sandip, I forgot to mention that is not required to use a visualization to get the data. ChartFactor can obtain data without visualizing:

cf.provider('Elastic')
.source('my-source')
.groupby(group1)
.metrics(metric1)
.execute()
.then(response => console.log(response.data))