Highcharts CSS Styles When Exporting

Highcharts css styles when exporting

You can pass your CSS styles in your post request to export server.

var options = {
chart: {},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
]
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
type: 'column'
}]
}

var chart = Highcharts.chart('container', options);

var data = {
options: JSON.stringify(options),
resources: {
// You can add your CSS styles here
css: ".highcharts-background { fill: #efefef; stroke: #a4edba; stroke-width: 2px}"
},
filename: 'test.png',
type: 'image/png',
async: true
}

var exportUrl = 'https://export.highcharts.com/';
$.post(exportUrl, data, function(data) {
var imageUrl = exportUrl + data;
var urlCreator = window.URL || window.webkitURL;
document.querySelector("#image").src = imageUrl;
fetch(imageUrl).then(response => response.blob()).then(data => {console.log(data)});
})

Live example: https://jsfiddle.net/nfbcq865/

HighChart Title text implemented HTML Style is not applying in exporting files

Answer of @Halvor Strand hits the home, but additionally there is need to change the title structure, because SVG won't generate correctly during exporting. It's happening because </br>'s, but to solve this problem, for example you can place every title line in different <span> element with style="display: block;" set on it. Take a look on the code:

    title: {
useHTML: true,
text: '<span style="display: block;">Header Text in Line1</span><span style="display: block;">Line 2 Text</span><span style="display: block;">Line 3 Text</span>',
style: {
"text-align": "center"
}
}

Live example: http://jsfiddle.net/m052y9ud/

HighChart - How to apply override Subtitle style css in HighChart Print

You should position the subtitle element by x property:

subtitle: {
useHTML: true,
align: 'left',
text: 'SubTitle: line1 <br/> SubTitle: line2 ',
x: 100
}

Live demo: http://jsfiddle.net/BlackLabel/u4qpod2a/

You can also look at this topic: Highcharts css styles when exporting, to find out how to export chart with css styles.



Related Topics



Leave a reply



Submit