I want to export multiple highcharts with textarea to multiple pdf files. How will I convert multiple highcharts with textarea to multiple pdf files?
$(function() {
Highcharts.getSVG = function(chart, text) {
var svgArr = [],
top = 0,
width = 0,
txt;
var svg = chart.getSVG();
svg = svg.replace('<svg', '<g transform="translate(0,' + top + ')" ');
svg = svg.replace('</svg>', '</g>');
top += chart.chartHeight;
width = Math.max(width, chart.chartWidth);
svgArr.push(svg);
txt = '<text x= "' + 0 + '" y = "' + (top + 20) + '" styles = "' + text.attributes.style.value + '">' + $(text).val() + '</text>';
top += 200;
console.log(txt.indexOf('\n'))
svgArr.push(txt);
return '<svg height="' + top + '" width="' + width + '" version="1.1" xmlns="http://www.w3.org/2000/svg">' + svgArr.join('') + '</svg>';
};
Highcharts.getSVG = function(chart, text) {
var svgArr = [],
top = 0,
width = 0,
txt;
var svg = chart.getSVG();
svg = svg.replace('<svg', '<g transform="translate(0,' + top + ')" ');
svg = svg.replace('</svg>', '</g>');
top += chart.chartHeight;
width = Math.max(width, chart.chartWidth);
svgArr.push(svg);
txt = '<text x= "' + 0 + '" y = "' + (top + 20) + '" styles = "' + text.attributes.style.value + '">' + $(text).val() + '</text>';
top += 200;
console.log(txt.indexOf('\n'))
svgArr.push(txt);
return '<svg height="' + top + '" width="' + width + '" version="1.1" xmlns="http://www.w3.org/2000/svg">' + svgArr.join('') + '</svg>';
};
Highcharts.exportChartWithText = function(chart, text, options) {
// Merge the options
options = Highcharts.merge(Highcharts.getOptions().exporting, options);
// Post to export server
Highcharts.post(options.url, {
filename: options.filename || 'chart',
type: options.type,
width: options.width,
svg: Highcharts.getSVG(chart, text)
});
};
Highcharts.exportChartWithText = function(chart, text, options) {
// Merge the options
options = Highcharts.merge(Highcharts.getOptions().exporting, options);
// Post to export server
Highcharts.post(options.url, {
filename: options.filename || 'chart',
type: options.type,
width: options.width,
svg: Highcharts.getSVG(chart, text)
});
};
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: 'Stacked bar chart'
},
xAxis: {
categories: ['PreviousMonthutilizationforCPU', 'CurrentMonthUtilizationforCPU', 'Week2', 'Week2', 'Week3', 'Week4']
},
yAxis: {
min: 0,
title: {
text: 'POD'
}
},
tooltip: {
formatter: function() {
return '<b>' + this.x + '</b><br/>' +
this.series.name + ': ' + this.y + '<br/>' +
'Total: ' + this.point.stackTotal;
}
},
legend: {
reversed: true
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
data: [1, 2, 3, 3, 4]
}],
exporting: {
enabled: true
}
});
chart = new Highcharts.Chart({
chart: {
renderTo: 'container1',
type: 'column'
},
title: {
text: 'Stacked bar chart'
},
xAxis: {
categories: ['PreviousMonthutilizationforCPU', 'CurrentMonthUtilizationforCPU', 'Week2', 'Week2', 'Week3', 'Week4']
},
yAxis: {
min: 0,
title: {
text: 'POD'
}
},
tooltip: {
formatter: function() {
return '<b>' + this.x + '</b><br/>' +
this.series.name + ': ' + this.y + '<br/>' +
'Total: ' + this.point.stackTotal;
}
},
legend: {
reversed: true
},
plotOptions: {
series: {
stacking: 'normal'
}
},
series: [{
data: [1, 2, 3, 3, 4]
}],
exporting: {
enabled: true
}
});
var text = document.getElementById('txt');
$("#export2pdf").click(function() {
Highcharts.exportChartWithText(chart, text, {
type: 'application/pdf',
filename: 'wow-pdf'
});
});
$("#export2pdf").click(function() {
Highcharts.exportChartWithText(chart, text, {
type: 'application/pdf',
filename: 'wow-pdf'
});
});
});
First part of an answer is here: Export Multiple highcharts with custom text into pdf
To answer the second question, asked in your comment (about breaking the lines) - you need to change the code a little bit. You may use tspan for breaking your lines. You should also remember about changing width of your label with every new line:
http://jsfiddle.net/6m2rneL8/35/