1

素顔チャートを画像としてエクスポートできません。

categoryModelプライムショーケースと同じです。

エクスポートするには依存ライブラリが必要ですか?

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    ......
    template="/common/commonLayout.xhtml">
    <ui:define name="content">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript">
            //<![CDATA[
            function exportChart() {
                //export image
                $('#output').empty().append(chart.exportAsImage());

                //show the dialog
                dlg.show();
            }
            //]]>
        </script>

        <h:form enctype="multipart/form-data">
            <p:barChart id="basic" value="#{ChartActionBean.categoryModel}" legendPosition="ne"  
                        title="Bar Chart" widgetVar="chart" animate="true" yaxisLabel="Number of Count"/>
            <p:commandButton type="button" value="Export" icon="ui-icon-extlink" onclick="exportChart()"/>  

            <p:dialog widgetVar="dlg" showEffect="fade" modal="true" header="Chart as an Image">  
                <p:outputPanel id="output" layout="block" style="width:500px;height:300px"/>  
            </p:dialog>  
        </h:form>
    </ui:define>
</ui:composition>
4

2 に答える 2

3

Showcase と Export ボタンと OutputPanel はラップされていないため、$('#output') は期待される要素を選択して画像を追加できます。

しかし、あなたのケースでは、これらのコンポーネントをラップしているので、JSF は j_idt10 のようなフォームの ID を生成し、コンポーネントの ID "output" は "j_idt10:output" になります。

これを修正するには:

<h:form id="form1">
  //chart
  // export button
  //dialog containing outputPanel
</h:form>

そしてJavaScriptで:

function exportChart() {
     $('#form1\\:output').empty().append(chart.exportAsImage());
     dlg.show();
}

または、単純に$('#output').empty().append(chart.exportAsImage()); の外に置きます。期待どおりに動作します。

于 2013-08-18T08:11:49.363 に答える
0

また、モデルを指定するには、 valueではなくmodel属性を使用すると思います。したがって、あなたの場合は次のようになります。

<p:barChart id="basic" model="#{ChartActionBean.categoryModel}" legendPosition="ne" title="Bar Chart" widgetVar="chart" animate="true" yaxisLabel="Number of Count"/>
于 2015-05-29T13:26:06.877 に答える