柱状图在 jsreport 中使用 apexchart

huangapple go评论95阅读模式
英文:

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

{
    &quot;Completedcalls&quot;: [
        {
        &quot;Bloemfontein&quot;: 2
        },
        {
            &quot;Mafube&quot;: 5
        },
        {
            &quot;Phumelela&quot;: 6
        },
        {
            &quot;Total&quot;: 13
        }
    ]
}

and here is the code for plotting the chart

&lt;script src=&quot;https://cdn.jsdelivr.net/npm/apexcharts&quot;&gt;&lt;/script&gt;
      &lt;div id=&quot;myFirstChart&quot;&gt;&lt;/div&gt;
        &lt;script&gt;
          console.log(&#39;mango jerry&#39;)
          var a = {{{ReadData Completedcalls}}};
        var options = {
          chart: {
            type: &#39;bar&#39;,
            toolbar: {
              show: false,
            },
          },
          plotOptions: {
            bar: {
              horizontal: false
            }
          },
          series: [{
            data: {{{ReadData Completedcalls}}}
          }]
        }

        var element = document.querySelector(&quot;#myFirstChart&quot;);
        console.log(element);
        var chart = new ApexCharts(element, options);

        chart.render();
        &lt;/script&gt;

答案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: &#39;bar&#39;,
    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.

huangapple
  • 本文由 发表于 2023年3月8日 19:03:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75672186.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定