Search code examples
javascriptpdfapexdocument.writeapexcharts

How to pass width to apexChart container via document.write (pdf printing)?


everyone!

I am trying to configure a PDF output of HTML page. On this page I have an ApexChart, which has a width of '100%' (in JS options).

var options = {
  chart: {
    width:'100%',
    type: "line",
    animations: {
      enabled: false
    },
    toolbar: {
      show: true,
    },
    zoom: {
      enabled: false
    }
  },

When the page is printed, I want to resize the chart by passing another width value to its container div element, but it does not seem to work, because the chart does not resize.

pdf.document.write(`<style>
    #grafiksOuterContainer{
      width:200px;
    }
</style>`);

The codepen demo is attached below. I hope that someone has dealt with this problem. Thank you in advance

Demo


Solution

  • ApexChart hard coded the size (height, width) into it's svg container, you need to regenerate the chart for printing. chart.js has resize() feature, but ApexChart has no such feature. – Jack Ting May 11, 2020 at 19:28