我想使用primefaces 6.1导出条形图。这是我定义图表的方式:
<p:chart type="bar" extender="myExtender" style="max-width: 100%;height: auto;" model="#{myBean.myModel}" responsive="false" shadow="false" widgetVar="myChart" />
我正在尝试使用以下代码导出图表:
if (PF('myChart') !== undefined && PF('myChart').exportAsImage().src.startsWith('data:image')) {
// do something with the data
}
生成图表时,它在UI中具有数据。但是,当exportAsImage()函数执行时,我看到一个错误:
Failed to execute 'drawImage' on 'CanvasRenderingContext2d': The image argument is a canvas element with a width or height of 0.
我认为该问题可能与时间相关。但是,如果我创建一个直接调用jqplotToImageElem()的javascript函数,则会出现相同的错误。
setTimeout(function () {PF('myChart').jq.jqplotToImageElem();}, 20000);
有趣的是,当我生成一个饼图时,我没有看到该错误,并且能够观察到exportAsImage()函数正常工作。这是我的饼图代码:
<p:chart type="pie" extender="anotherExtender" style="max-width: 100%;height: auto;" responsive="true" shadow="false" widgetVar="myPieChart" model="#{myBean.pieModel}" />
为了使用Primefaces提供的exportAsImage()函数能够像饼图一样导出条形图,我该怎么办?
这仅适用于PrimeFaces 8.0的PrimeFaces展示柜中的我