Created
April 4, 2018 20:30
-
-
Save YorkAARGH/b02c35c7ccfb56c1fcbc498446af25cf to your computer and use it in GitHub Desktop.
Highcharts-Structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const exporter = require('highcharts-export-server'); | |
const { promisify } = require('util'); | |
const { writeFile } = require('fs-nextra'); | |
const render = promisify(exporter.export); | |
exporter.initPool(); | |
module.exports = class Chart { | |
constructor() { | |
this.type = 'png'; | |
this.options = {}; | |
this.options.credits = {}; | |
this.options.credits.enabled = false; | |
this.options.chart = {}; | |
this.options.chart.backgroundColor = '#2C2F33'; | |
this.options.chart.borderColor = '#3498DB'; | |
this.options.chart.borderWidth = 2; | |
this.options.title = {}; | |
this.options.title.style = {}; | |
this.options.title.style.color = '#FFFFFF'; | |
this.options.title.style.fontWeight = 'bold'; | |
this.options.xAxis = {}; | |
this.options.xAxis.type = 'datetime'; | |
this.options.xAxis.labels = { style: { color: '#FFFFFF' } }; | |
this.options.yAxis = {}; | |
this.options.yAxis.title = { text: null }; | |
this.options.yAxis.labels = { style: { color: '#FFFFFF' } }; | |
this.options.legend = {}; | |
this.options.legend.itemStyle = {}; | |
this.options.legend.itemStyle.color = '#FFFFFF'; | |
this.options.legend.itemStyle.fontWeight = 'bold'; | |
this.options.plotOptions = {}; | |
this.options.plotOptions.series = {}; | |
this.options.series = []; | |
} | |
async generateChart(location) { | |
const res = await render(this); | |
const data = res.data.replace(/^data:image\/\w+;base64,/, ''); | |
return writeFile(location, data, 'base64'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment