How to use the highcharts-export-server.export function in highcharts-export-server

To help you get started, we’ve selected a few highcharts-export-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github whatl3y / restcharts / src / routes / 0.._chart_[colon]type..get.js View on Github external
export default async function Chart(req, res) {
  try {
    const routeParams = req.params
    const type        = routeParams.type

    const body        = req.query || {}
    const chartData   = (body.data || '').split(',')
    const chartColor  = (body.hexcolor) ? `#${body.hexcolor}` : null
    const height      = (body.height) ? parseInt(body.height) : null
    const width       = (body.width) ? parseInt(body.width) : null
    const fillOpacity = (body.opacity) ? parseFloat(body.opacity) : null

    if (chartData.length <= 1)
      return res.status(400).json({ error: 'Please pass valid data.' })

    exporter.export({ type: 'png', options: ChartConfig.getChartConfig(chartData, {
        type: type,
        color: chartColor,
        opacity: fillOpacity,
        height: height,
        width: width
      })}, function(err, response) {
        //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)

        const imageBase64 = response.data
        const imageBuffer = Buffer.from(imageBase64, 'base64')
github Bastian / bStats / util / chartRenderer.js View on Github external
colors: options.colors || ["#F44336", "#2196F3", "#4CAF50", "#FF9800", "#FFEB3B", "#009688",
                "#E91E63", "#795548", "#607D8B", "#3F51B5", "#9C27B0"]
        })
    };

    for (let i = 0; i < data.length; i++) {
        exportSettings.options.series.push({
                name : options.lineName[i] || '',
                data : data[i],
                type: 'area',
                tooltip: {
                    valueDecimals: 0
                }
            });
    }
    exporter.export(exportSettings, function (err) {
        if (err) {
            return callback(err);
        }
        fs.readFile(path.resolve(__dirname + '/../' + fileName), 'utf8', function(err, contents) {
            if (err) {
                return callback(err);
            }
            fs.unlink(path.resolve(__dirname + '/../' + fileName), function(err) {
                if (err) {
                    console.log(err);
                }
            });
            contents = contents.replace(fileName, '<a xlink:title="bStats.org" xlink:href="https://bStats.org/">View full stats at bStats.org</a>');
            callback(null, { result: contents });
        });
    });
github Bastian / bStats / util / chartRenderer.js View on Github external
series : [{
                name : options.lineName || '',
                data : data,
                type: 'area',
                tooltip: {
                    valueDecimals: 0
                }
            }]
        },
        globalOptions: JSON.stringify({
            colors: options.colors || ["#F44336", "#2196F3", "#4CAF50", "#FF9800", "#FFEB3B", "#009688",
                "#E91E63", "#795548", "#607D8B", "#3F51B5", "#9C27B0"]
        })
    };
    exporter.export(exportSettings, function (err) {
        if (err) {
            return callback(err);
        }
        fs.readFile(path.resolve(__dirname + '/../' + fileName), 'utf8', function(err, contents) {
            if (err) {
                return callback(err);
            }
            fs.unlink(path.resolve(__dirname + '/../' + fileName), function(err) {
                if (err) {
                    console.log(err);
                }
            });
            contents = contents.replace(fileName, '<a xlink:title="bStats.org" xlink:href="https://bStats.org/">View full stats at bStats.org</a>');
            callback(null, { result: contents });
        });
    });
github whatl3y / restcharts / src / routes / 0.._chart_[colon]type..all.js View on Github external
return new Promise((resolve, reject) =&gt; {
    try {
      const routeParams = req.params
      const body        = req.query || req.body || {}
      const chartType   = routeParams.type || body.type
      const rawConfig   = jsonParseFallback(body.raw || {}, {})
      const chartData   = (body.data || '').split(',')

      delete(body.data)

      if (chartData.length &lt;= 1 &amp;&amp; !rawConfig.series)
        return res.status(400).json({ status: 400, error: `Please pass valid data. If you passed a 'raw' param with data populated in the 'series' key, there is likely something wrong with the JSON config you passed.` })

      const finalConfig = ChartHelpers.getConfig(chartData, Object.assign(body, { type: chartType }), rawConfig)
      exporter.export({ type: 'png', options: finalConfig}, function(err, response) {
        if (err) {
          res.status(500).json({ status: 500, error: err })
          return reject(err)
        }

        const imageBase64 = response.data
        const imageBuffer = Buffer.from(imageBase64, 'base64')

        res.setHeader('Content-Type', 'image/png')
        res.send(imageBuffer)
        resolve(imageBuffer)
      })

    } catch(err) {
      res.status(500).json({ status: 500, error: err })
      reject(err)
github LeaPhant / flowabot / osu.js View on Github external
type: 'datetime',
                        dateTimeLabelFormats: {
                            month: '%M:%S',
                            year: '%M:%S',
                            day: '%M:%S',
                            minute: '%M:%S',
                            second: '%M:%S',
                            millisecond: '%M:%S'
                        }
                    },
                    series: [{ showInLegend: false, data: bpms }]
                },
                themeOptions: CHART_THEME
            };

            highcharts.export(highcharts_settings, (err, res) => {
                if(err) cb('An error occured creating the graph')
                else cb(null, res.data);
            });
        }catch(e){
            cb('An error occured creating the graph');
            helper.error(e);
            return;
        }
    },

highcharts-export-server

Convert Highcharts.JS charts to static image files.

MIT
Latest version published 3 months ago

Package Health Score

81 / 100
Full package analysis

Popular highcharts-export-server functions

Similar packages