Jérôme
Jérôme

Reputation: 2090

Highcharts export to svg

Based upon this tutorial, I am successfully running the following (simplified) example :

phantomjs highcharts-convert.js -infile options1.json -outfile chart1.png -width 300 -constr Chart

I can change the outputfile extension to .jpg or .pdf and get the expected output but when I change it to .svg the chart1.svg file that is successfully created is empty.

From highcharts-convert.js, here are the instructions which fails at writing that file :

fs = require('fs');
...
svgFile = fs.open(output, "w");
svgFile.write(svg);

I checked console.log(svg) and svgis not empty, so the guilty one is svgFile.write(svg); but why?

I am running Mac OS X.

Upvotes: 0

Views: 1821

Answers (1)

Paweł Fus
Paweł Fus

Reputation: 45079

This is bug in Highcharts, after writing to the stream, stream should be closed, so this should look this way:

                if (!runsAsServer) {
                    // write the file
                    svgFile = fs.open(output, "w");
                    svgFile.write(svg);
                    svgFile.close(); //add this line
                    exit(output);
                } else {
                    // return the svg as a string
                    exit(svg);
                }

Reported: https://github.com/highslide-software/highcharts.com/issues/1869

Upvotes: 2

Related Questions