Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts export chart exportSettings with svg file

I would like to render map file in the back with a .Net Core project

So, the purpose is to execute Highmaps library on a Javascript middleware, and export the svg file to the "node-export-server".

I have a API which receive from the client some data. I would like to generate the SVG map file with Highmap library and then send to anonother API which will contain a middleware to execute the node module gor the PNG/JPG/... export.

What is the way to pass a svg file to the "node-export-server" module ? I read the associate docs but I didn't found the way... (https://github.com/highcharts/node-export-server/blob/master/README.md)

I would like to pass my SVG file with this sample.

//Include the exporter module
const exporter = require('highcharts-export-server');

//Export settings 
var exportSettings = {
    type: 'png',
    options: {
        title: {
            text: 'My Chart'
        },
        xAxis: {
            categories: ["Jan", "Feb", "Mar", "Apr", "Mar", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
        },
        series: [
            {
                type: 'line',
                data: [1, 3, 2, 4]
            },
            {
                type: 'line',
                data: [5, 3, 4, 2]
            }
        ]
    }
};

//Set up a pool of PhantomJS workers
exporter.initPool();

//Perform an export
/*
    Export settings corresponds to the available CLI arguments described
    above.
*/
exporter.export(exportSettings, function (err, res) {
    //The export result is now in res.
    //If the output is not PDF or SVG, it will be base64 encoded (res.data).
    //If the output is a PDF or SVG, it will contain a filename (res.filename).

    //Kill the pool when we're done with it, and exit the application
    exporter.killPool();
    process.exit(1);
});
like image 867
Blennouill Avatar asked Aug 11 '17 07:08

Blennouill


People also ask

How do I get SVG from Highcharts?

Re: Get Highcharts SVG Code as a String You can trigger an export by calling chart. export(<mime type>) or grab the svg in js by calling chart. getSVG() (where 'chart' is, of course, the variable name of an instance of HC).

Can Highcharts be used in server?

It supports PNG, JPEG, SVG, and PDF output; and the input can be either SVG, or JSON-formatted chart options. The application can be used either as a CLI (Command Line Interface), as an HTTP server, or as a node.


1 Answers

Well this might not be exactly the full answer, but it may guide you in the right direction: Take a look at https://github.com/aspnet/JavaScriptServices which provide a way to pass code to nodejs (even though it is about server side rendering, the principle is similar). Then you can pass arguments to nodejs the "same way" you may pass it through CLI.

like image 184
theCuriousOne Avatar answered Oct 03 '22 10:10

theCuriousOne