export multiple highcharts with text area for thier highcharts to multiple PDF file -
i want multiple highcharts textarea multiple pdf file . how wil convert multiple highcharts textarea multiple pdf $(function() { highcharts.getsvg = function(chart, text) { var svgarr = [], top = 0, width = 0, txt; var svg = chart.getsvg(); svg = svg.replace('', '');
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 options options = highcharts.merge(highcharts.getoptions().exporting, options); // post 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 options options = highcharts.merge(highcharts.getoptions().exporting, options); // post 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 answer here: export multiple highcharts custom text pdf
to answer second question, asked in comment (about breaking lines) - need change code little bit. may use tspan breaking lines. should remember changing width of label every new line:
highcharts.getsvg = function(charts, texts) { var svgarr = [], top = 0, width = 0, txt, numberoflines; highcharts.each(charts, function(chart, i) { 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 = texts[i]; value = $(txt).val().replace(/\n/g, '</tspan><tspan x="0" dy="1.2em">'); numberoflines = $(txt).val().split("\n").length; txt = '<text x= "' + 0 + '" y = "' + (top + 20) + '" styles = "' + txt.attributes.style.value + '"><tspan x="0" dy="1.2em">' + value + '</tspan></text>'; top += 1.2 * 16 * numberoflines + 20; svgarr.push(txt); }); return '<svg height="' + top + '" width="' + width + '" version="1.1" xmlns="http://www.w3.org/2000/svg">' + svgarr.join('') + '</svg>'; };
Comments
Post a Comment