英文:
Bar chart in jsreport using apexchart
问题
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<div id="myFirstChart"></div>
<script>
  console.log('mango jerry');
  var a = [{"Bloemfontein": 2},{"Mafube": 5},{"Phumelela": 6},{"Total": 13}];
  var options = {
    chart: {
      type: 'bar',
      toolbar: {
        show: false,
      },
    },
    plotOptions: {
      bar: {
        horizontal: false
      }
    },
    series: [{
      data: [{"Bloemfontein": 2},{"Mafube": 5},{"Phumelela": 6},{"Total": 13}]
    }]
  }
  var element = document.querySelector("#myFirstChart");
  console.log(element);
  var chart = new ApexCharts(element, options);
  chart.render();
</script>
英文:
I trying to include a bar chart in my jsreport using apexchart but I keep getting chart without any bars or labels. I don't know what I am doing wrong. The engine is handlebars and the recipe is chrome-pdf.
here is the data
{
    "Completedcalls": [
        {
        "Bloemfontein": 2
        },
        {
            "Mafube": 5
        },
        {
            "Phumelela": 6
        },
        {
            "Total": 13
        }
    ]
}
and here is the code for plotting the chart
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
      <div id="myFirstChart"></div>
        <script>
          console.log('mango jerry')
          var a = {{{ReadData Completedcalls}}};
        var options = {
          chart: {
            type: 'bar',
            toolbar: {
              show: false,
            },
          },
          plotOptions: {
            bar: {
              horizontal: false
            }
          },
          series: [{
            data: {{{ReadData Completedcalls}}}
          }]
        }
        var element = document.querySelector("#myFirstChart");
        console.log(element);
        var chart = new ApexCharts(element, options);
        chart.render();
        </script>
答案1
得分: 1
这很可能是因为图表库使用动画,而在触发 PDF 打印时动画尚未完成。
尝试禁用动画使用
var options = {
  chart: {
    type: 'bar',
    toolbar: {
      show: false,
    },
    animations: {
      enabled: false
    }
  },
  ...
}
如果您遇到需要等待某些异步任务完成的情况,您可以使用chrome-pdf recipe printing triggers来延迟打印。
英文:
That is most likely because the charting library uses animation which isn't yet finished when the printing of the pdf is triggered.
Try to disable animation using
var options = {
  chart: {
    type: 'bar',
    toolbar: {
      show: false,
    },
    animations: {
      enabled: false
    }
  },
  ...
}
In case you get into a situation when you need to wait for some async task, you can use chrome-pdf recipe printing triggers to postpone printing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论