2016-08-29 4 views
0

複数のハイパーチャートを複数のpdfファイルに書きたい。私は複数のPDF $にテキストエリアで複数highchartsを変換する方法WIL (関数(){ Highcharts.getSVG =関数(チャート、テキスト){ VAR svgArr = []、 トップ= 0、 幅= 0、 TXT ; するvar SVG = chart.getSVG(); SVG = svg.replace( ''、 '');ハイチャートのテキスト領域を複数のPDFファイルにエクスポートする

 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' 
     }); 
     }); 
    }); 
+2

同様のトピック:http://stackoverflow.com/questions/39171077/export-multiple-highcharts-with-customあなたはまた、すべての新しい行を使用してラベルの幅を変えることについて忘れてはなりません-text-into-pdf –

+0

次のように入力した場合、テキストエリア1.カスタムテキスト1 2. PDFにエクスポート中のカスタムテキスト2私は1行になります。カスタムテキスト1 2.カスタムテキスト2を1行で区切ります。別の行の必要性。あなたは私を案内してくれますか? –

+0

私は、複数のハイチャートをテキストエリアを持つ複数のpdfにしたいと思います。私のコードは以下の通りですが、上の例では動作しません。 –

答えて

0

答えの最初の部分はここにある: Export Multiple highcharts with custom text into pdf

は、第二に答えるために質問、あなたのcommeで尋ねられたnt(改行について) - コードを少し変更する必要があります。あなたの回線を切断するのにtspanを使用することができます。

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>'; 
    }; 

http://jsfiddle.net/6m2rneL8/35/

+0

素晴らしい! GrzegorzBlachliński、あなたは私をたくさん助けてくれました。 –

+0

私はHTMLページに50のチャートを持っています。すべてのチャートをpdfにエクスポートすると、すべてのチャートがpdfで適切にレンダリングされます。しかし、これらのチャートは1ページだけでレンダリングされます。改ページはありません。それが可能なら、私を助けてください。ありがとう@Grzegorz –

+0

私はあなたが以前に尋ねたものとはまったく別の質問だと思う、あなたはここで似たようなトピックを見つけることができます:http://stackoverflow.com/questions/32614717/export-multiple-highcharts-to-multi-page-pdf –

関連する問題