Export a chart to excel / pdf ?

A free public discussion forum for the JFreeChart class library.

Export a chart to excel / pdf ?

Postby mohit_singhal » Thu Mar 08, 2007 11:16 am

Hi,

Can anybody help me in exporting a generated chart (or dataset) to excel file & pdf file.

Thanks in advance,
Mohit
mohit_singhal
 
Posts: 14
Joined: Tue Nov 28, 2006 11:07 am

Postby djprice » Thu Mar 08, 2007 1:46 pm

I am using iText (http://www.lowagie.com/iText/) to create and write to a pdf.

First I have an accessor class:
private byte resultGraph3[];
public byte[] getResultGraph3()
{
return (this.resultGraph3);
}
public void setResultGraph3(byte[] byteIn)
{
this.resultGraph3 = byteIn;
}


Then I write the chart to the byte[] in the accessor class:
JFreeChart chart = createChart3(dataset, ac);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int width = 700;
int height = 500;
ChartUtilities.writeChartAsPNG(bos, chart, width, height);
ac.setResultGraph3(bos.toByteArray());
bos.close();

Now I can use iText to write out the image inside the PDF:
Image graph1 = Image.getInstance(ac.getResultGraph3());
vTable1.addCell(graph1);
document.add(vTable1);
djprice
 
Posts: 7
Joined: Thu Mar 01, 2007 1:39 pm

Postby mohit_singhal » Thu Mar 08, 2007 1:50 pm

Thanks buddy .. will try n implement this ... can u please let me know how to export to excel.
mohit_singhal
 
Posts: 14
Joined: Tue Nov 28, 2006 11:07 am

Postby djprice » Thu Mar 08, 2007 1:58 pm

Unfortunately, I cannot help with Excel since I have never exported a chart to Excel. Maybe someone else on this forum has and can post a suggestion.
djprice
 
Posts: 7
Joined: Thu Mar 01, 2007 1:39 pm

Postby mohit_singhal » Thu Mar 08, 2007 2:04 pm

okies ... not a problem :)
mohit_singhal
 
Posts: 14
Joined: Tue Nov 28, 2006 11:07 am

Postby jwenting » Thu Mar 08, 2007 2:27 pm

Excel generates charts based on data from an excel workbook.
You could use something like POI or XSL:FO to generate an Excel workbook and probably to put in the commands to generate the chart there.
jwenting
 
Posts: 157
Joined: Sat Jul 15, 2006 7:46 am

Postby mohit_singhal » Thu Mar 08, 2007 3:20 pm

actually, I have to export in such a way that data from chart is displayed in tabular form. I mean the form in which it is stored in the dataset. :)
mohit_singhal
 
Posts: 14
Joined: Tue Nov 28, 2006 11:07 am

Postby david.gilbert » Thu Mar 08, 2007 5:00 pm

Regarding PDF, iText has a nice PdfGraphics2D class which allows you to create charts in vector format within the PDF, which allows nicer scaling (compared to embedding an image in the PDF file).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11352
Joined: Fri Mar 14, 2003 10:29 am

Postby jwenting » Mon Mar 12, 2007 9:29 am

mohit_singhal wrote:actually, I have to export in such a way that data from chart is displayed in tabular form. I mean the form in which it is stored in the dataset. :)


Well, that's not what JFreeChart is for.
Export it from the layer which calls JFreeChart to create the chart instead.
jwenting
 
Posts: 157
Joined: Sat Jul 15, 2006 7:46 am

Postby Kousu » Mon Mar 12, 2007 9:41 pm

So you don't *actually* need Excel, do you? Just use .csv (which Excel can open but does not lock you in to Microsoft). Check out http://opencsv.sf.net, it's very small and nice and clean.
Kousu
 
Posts: 63
Joined: Wed Mar 07, 2007 10:40 pm


Return to JFreeChart - General

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], Yahoo [Bot] and 11 guests