PrimeFaces 7 chart.exportAsImage метод создает неправильное изображение - PullRequest
0 голосов
/ 23 марта 2020

Я разработал процедуру exportAsImage для экспорта диаграммы из моего приложения.

Компонент диаграммы реализован для создания следующего графика: enter image description here

но когда я нажимаю кнопку сохранения, полученное изображение для экспорта выглядит так: enter image description here

Мой компонент диаграммы реализован следующим образом:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">


<f:view>
   <h:head>

      <script type="text/javascript"  src="js/charts.js" ></script>

      <!--  -->
      <title>my app</title>
   </h:head>

   <h:body>



      <!-- Dialog for exported chart -->
      <p:dialog widgetVar="dlgExport" showEffect="fade" modal="true" header="Chart as an Image">
         <p:outputPanel id="exportChart" binding="#{exportChart}" layout="block" style="width:1200px;height:800px" />
      </p:dialog>

     <!-- My chart -->
       <p:chart id="seriesChart" binding="#{seriesChart}" type="line" model="#{statSeriesBean.model}"
                responsive="true" style="height: 90%" widgetVar="seriesChart"  />

       <p:commandButton type="button"  icon="fa fa-save" onclick="exportChart()"/>




   </h:body>

</f:view>
</html>

In Чтобы вызвать метод exportAsImage и просмотреть результат в outputPanel, функция exportChart () JS вызывается событием onClick кнопки. Функция exportChart, реализованная в диаграммах. js, показана здесь:

    function exportChart() {
$('#exportChart').empty().append(PF('seriesChart').exportAsImage());

       PF('dlgExport').show();
    }

Здесь находятся бины поддержки:

    @ManagedBean(name="statSeriesBean")
@ViewScoped
public class StatSeriesBean implements Serializable {

    private LineChartModel model;



    LineChartSeries series1;

    //StatSeries is an entity class for managing data.
    private List<StatSeries> statData;
    private StatSeries selectedStat;




    @PostConstruct
    public void init(){
        System.out.println("statSeries - init");
        model = new LineChartModel();
        series1 =new LineChartSeries();
        series1.set("0",0.0);
        model.addSeries(series1);
        //.... producing data ....


    }


}

Есть идеи?

...