Jump to content
Software FX Community

How to export SVG chart?


User (Legacy)

Recommended Posts

My enterprise is currenty evaluating ChartFX for our charting solution.

Part of the functionality we need is the ability to export charts to SVG

format. I have been unable to get this functionality to work at all in

ChartFX. This is a show stopper for us. According to the docs it appears

that this should be possible. How is this done? I have tried the following

code with no success.

Edward

/**

* This method *attempts* to export a chart in SVG format.

*

*/

private void exportSVGChart(){

try

{

// Create a new chart

chart1 = new Chart();

// Give it some data

chart1.openData(COD.VALUES, 1, 100);

for (int i=0;i<99;i++)

{

chart1.setValue(0, i, java.lang.Math.random()* 80);

}

chart1.closeData(COD.VALUES);

// Create an SCGWriter

SVGWriter w = new SVGWriter();

// Assign it to the chart

chart1.setOutputWriter(w);

// Set the image tags to SVG. I don't know if this is necessary or

// even axactly what this does as the docs don't specify!

chart1.setImgTags("SVG");

// Attempt to export using exportChart...

// *** THE FOLLOWING LINE EXPORTS THE CHART CORRECTLY CONFIGURED WITH

DATA, BUT IN JPG FORMAT!!!!

// WHY??? I EXPECTED .SVG!

chart1.exportChart(FileFormat.EXTERNAL, "C:\\exportedChart1.svg");

// exportChart didn't work so try getHtmlDataEx...

FileOutputStream chartStream = new

FileOutputStream("C:\\exportedChart2.svg");

FileOutputStream mapStream = new

FileOutputStream("C:\\exportedChart2Map.map");

FileOutputStream tagStream = new

FileOutputStream("C:\\exportedChart2Tag.tag");

// *** THE FOLLOWING LINE ALSO EXPORTS THE CHART IN .JPG FORMAT, BUT EVEN

// WORSE, THE CHART IS EMPTY AND HAS NO DATA AND NOT CONFIGURED!!!

// WHY???

//

// THE TAG FILE LOOKS LIKE THIS:

// <a href="http://www.softwarefx.com/upgradedevstudio/"><IMG SRC=""

border="0"></a>

chart1.getHtmlDataEx("400","400","SVG",chartStream,mapStream,tagStream);

// Flush and close the streams

chartStream.flush();

chartStream.close();

mapStream.flush();

mapStream.close();

tagStream.flush();

tagStream.close();

}catch(Exception e){

System.out.println("Exception: "+e);

}

}

Link to comment
Share on other sites

Hi Edward,

The issue with the exportChart looks like a bug, and I'm logging it for

correction. But I've manage to export the SGV using the GetHtmlDataEx

method. This is my JSP code:

<%@page import="SoftwareFX.ChartFX.*"%>

<%

Chart chart1 = new Chart();

// Give it some data

chart1.openData(COD.VALUES, 1, 100);

for (int i=0;i<99;i++)

{

chart1.setValue(0, i, java.lang.Math.random()* 80);

}

chart1.closeData(COD.VALUES);

chart1.getSeries(0).setColor(java.awt.Color.red);

java.io.ByteArrayOutputStream mapStream = new

java.io.ByteArrayOutputStream();

java.io.ByteArrayOutputStream tagStream = new

java.io.ByteArrayOutputStream();

String myChartName = "C:\\\\chart.svg";

java.io.FileOutputStream imgStream = new

java.io.FileOutputStream(myChartName);

chart1.setOutputWriter(new SVGWriter());

chart1.getHtmlDataEx("600","400","SVG", imgStream,mapStream,tagStream);

out.println("Done!");

%>

This has generated the attached chart.svg.

Regards,

GA

Software FX

"Edward Gemar" <egemar@zilliant.com> wrote in message

news:lKp5nyLzEHA.1120@webserver3.softwarefx.com...

> My enterprise is currenty evaluating ChartFX for our charting solution.

> Part of the functionality we need is the ability to export charts to SVG

> format. I have been unable to get this functionality to work at all in

> ChartFX. This is a show stopper for us. According to the docs it appears

> that this should be possible. How is this done? I have tried the

> following

> code with no success.

>

> Edward

>

>

> /**

> * This method *attempts* to export a chart in SVG format.

> *

> */

> private void exportSVGChart(){

>

> try

> {

> // Create a new chart

> chart1 = new Chart();

>

> // Give it some data

> chart1.openData(COD.VALUES, 1, 100);

> for (int i=0;i<99;i++)

> {

> chart1.setValue(0, i, java.lang.Math.random()* 80);

> }

> chart1.closeData(COD.VALUES);

>

> // Create an SCGWriter

> SVGWriter w = new SVGWriter();

>

> // Assign it to the chart

> chart1.setOutputWriter(w);

>

> // Set the image tags to SVG. I don't know if this is necessary or

> // even axactly what this does as the docs don't specify!

> chart1.setImgTags("SVG");

>

> // Attempt to export using exportChart...

>

> // *** THE FOLLOWING LINE EXPORTS THE CHART CORRECTLY CONFIGURED WITH

> DATA, BUT IN JPG FORMAT!!!!

> // WHY??? I EXPECTED .SVG!

> chart1.exportChart(FileFormat.EXTERNAL, "C:\\exportedChart1.svg");

>

> // exportChart didn't work so try getHtmlDataEx...

>

> FileOutputStream chartStream = new

> FileOutputStream("C:\\exportedChart2.svg");

> FileOutputStream mapStream = new

> FileOutputStream("C:\\exportedChart2Map.map");

> FileOutputStream tagStream = new

> FileOutputStream("C:\\exportedChart2Tag.tag");

>

> // *** THE FOLLOWING LINE ALSO EXPORTS THE CHART IN .JPG FORMAT, BUT

> EVEN

> // WORSE, THE CHART IS EMPTY AND HAS NO DATA AND NOT CONFIGURED!!!

> // WHY???

> //

> // THE TAG FILE LOOKS LIKE THIS:

> // <a href="http://www.softwarefx.com/upgradedevstudio/"><IMG SRC=""

> border="0"></a>

>

>

> chart1.getHtmlDataEx("400","400","SVG",chartStream,mapStream,tagStream);

>

> // Flush and close the streams

> chartStream.flush();

> chartStream.close();

>

> mapStream.flush();

> mapStream.close();

>

> tagStream.flush();

> tagStream.close();

>

> }catch(Exception e){

> System.out.println("Exception: "+e);

> }

> }

>

>

Link to comment
Share on other sites

It looks like there is a bug with the version of ChartFX for Java that

we were using. It is version 2004-A (as marked on the CD) and I believe was

sent to us from SoftwareFX as a promotion. Using this version, the code you

posted below still produces a .jpg file just like I was seeing before.

Given that you said the code below worked for you, I downloaded the latest

evaluation version of ChartFX for Java from the SoftwareFX site and ran your

code with it. That works! So definitly appears to be a bug in the version

on the CD that we received. Where is the versioning information for ChartFX

located (other than printed on the CD)?

Thanks,

Edward

"SoftwareFX Support" <noreply@softwarefx.com> wrote in message

news:Xx5u4PMzEHA.1116@webserver3.softwarefx.com...

> Hi Edward,

>

> The issue with the exportChart looks like a bug, and I'm logging it for

> correction. But I've manage to export the SGV using the GetHtmlDataEx

> method. This is my JSP code:

>

> <%@page import="SoftwareFX.ChartFX.*"%>

> <%

> Chart chart1 = new Chart();

>

> // Give it some data

> chart1.openData(COD.VALUES, 1, 100);

> for (int i=0;i<99;i++)

> {

> chart1.setValue(0, i, java.lang.Math.random()* 80);

> }

> chart1.closeData(COD.VALUES);

>

> chart1.getSeries(0).setColor(java.awt.Color.red);

>

> java.io.ByteArrayOutputStream mapStream = new

> java.io.ByteArrayOutputStream();

> java.io.ByteArrayOutputStream tagStream = new

> java.io.ByteArrayOutputStream();

>

> String myChartName = "C:\\\\chart.svg";

> java.io.FileOutputStream imgStream = new

> java.io.FileOutputStream(myChartName);

> chart1.setOutputWriter(new SVGWriter());

> chart1.getHtmlDataEx("600","400","SVG", imgStream,mapStream,tagStream);

>

> out.println("Done!");

> %>

>

> This has generated the attached chart.svg.

>

> Regards,

> GA

> Software FX

>

>

>

> "Edward Gemar" <egemar@zilliant.com> wrote in message

> news:lKp5nyLzEHA.1120@webserver3.softwarefx.com...

> > My enterprise is currenty evaluating ChartFX for our charting solution.

> > Part of the functionality we need is the ability to export charts to SVG

> > format. I have been unable to get this functionality to work at all in

> > ChartFX. This is a show stopper for us. According to the docs it

appears

> > that this should be possible. How is this done? I have tried the

> > following

> > code with no success.

> >

> > Edward

> >

> >

> > /**

> > * This method *attempts* to export a chart in SVG format.

> > *

> > */

> > private void exportSVGChart(){

> >

> > try

> > {

> > // Create a new chart

> > chart1 = new Chart();

> >

> > // Give it some data

> > chart1.openData(COD.VALUES, 1, 100);

> > for (int i=0;i<99;i++)

> > {

> > chart1.setValue(0, i, java.lang.Math.random()* 80);

> > }

> > chart1.closeData(COD.VALUES);

> >

> > // Create an SCGWriter

> > SVGWriter w = new SVGWriter();

> >

> > // Assign it to the chart

> > chart1.setOutputWriter(w);

> >

> > // Set the image tags to SVG. I don't know if this is necessary or

> > // even axactly what this does as the docs don't specify!

> > chart1.setImgTags("SVG");

> >

> > // Attempt to export using exportChart...

> >

> > // *** THE FOLLOWING LINE EXPORTS THE CHART CORRECTLY CONFIGURED WITH

> > DATA, BUT IN JPG FORMAT!!!!

> > // WHY??? I EXPECTED .SVG!

> > chart1.exportChart(FileFormat.EXTERNAL, "C:\\exportedChart1.svg");

> >

> > // exportChart didn't work so try getHtmlDataEx...

> >

> > FileOutputStream chartStream = new

> > FileOutputStream("C:\\exportedChart2.svg");

> > FileOutputStream mapStream = new

> > FileOutputStream("C:\\exportedChart2Map.map");

> > FileOutputStream tagStream = new

> > FileOutputStream("C:\\exportedChart2Tag.tag");

> >

> > // *** THE FOLLOWING LINE ALSO EXPORTS THE CHART IN .JPG FORMAT, BUT

> > EVEN

> > // WORSE, THE CHART IS EMPTY AND HAS NO DATA AND NOT CONFIGURED!!!

> > // WHY???

> > //

> > // THE TAG FILE LOOKS LIKE THIS:

> > // <a href="http://www.softwarefx.com/upgradedevstudio/"><IMG SRC=""

> > border="0"></a>

> >

> >

> >

chart1.getHtmlDataEx("400","400","SVG",chartStream,mapStream,tagStream);

> >

> > // Flush and close the streams

> > chartStream.flush();

> > chartStream.close();

> >

> > mapStream.flush();

> > mapStream.close();

> >

> > tagStream.flush();

> > tagStream.close();

> >

> > }catch(Exception e){

> > System.out.println("Exception: "+e);

> > }

> > }

> >

> >

>

>

>

post-2106-13922382286259_thumb.jpg

post-2106-13922385993241_thumb.jpg

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...