Exporting data within a DataSet

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dpenny
Posts: 1
Joined: Fri May 30, 2008 7:44 pm

Exporting data within a DataSet

Post by dpenny » Fri May 30, 2008 7:53 pm

Hi,

I'm fairly new to JFreeChart. I am doing a query into my database to build a DataSet then creating a chart, it works great. In addition to displaying a chart I'd also like to make the data for the chart available for download via CSV, Excel or some other common format. Is there any way to do this in JFreeChart and/or a library that can export this DataSet object to a local file?

Thanks,
Dan

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Re: Exporting data within a DataSet

Post by RichardWest » Fri May 30, 2008 10:29 pm

dpenny wrote:Is there any way to do this in JFreeChart and/or a library that can export this DataSet object to a local file?
Writing a CSV file is really easy since you are just writing the values as text seperated by commas and new-lines. Excel can read CSV files, so you would not have to worry about that. There are free libraries available for Java that would allow you to write native XLS files (for Excel version prior to Office 2007) with cell formatting etc. A Google search would be your best bet for finding a library with the features you want.

Whichever approach you take, you will have to write custom logic to export JFreeChart's dataset classes. The simplest approach would be to create your own custom class that extends a preexisting dataset class and add an export method you could call. All you would need to do is loop over every item of every series and write the value to the file (either as text or via a library).
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

Locked