首页 > 解决方案 > 加载页面时如何添加 JQPlot 类以隐藏所有图表线?

问题描述

我的 Primefaces JQPlot 折线图应用程序中有太多系列,我想加载已隐藏线条的图表;然后,用户将单击所需的图例以在图表中显示相应的线(参见此示例)。

模板.xhtml 文件:

<h:body onload="HideSeries()" >
    <!-- [unrelevant code ommited] -->
</h:body>

<script>
    function HideSeries() {
        $('#chartsFormID\\:lineChartID').toggleClass('jqplot-series-hidden');
    }
</script>

我的 index.xhtml 文件:

<h:form id="chartsFormID" >
    <p:accordionPanel multiple="false" dynamic="true" cache="true" >
        <p:tab title="myTab title">
            <p:chart type="line" id="lineChartID" model="#{bean.myChart}" />
        </p:tab>
    </p:accordionPanel>
</h:form>

不幸的是,它不起作用。

更好理解的图片

谁能帮帮我吗 ?

提前致谢。

标签: jquerychartsprimefacesjqplot

解决方案


要将类添加到所有元素,请尝试以下操作:

$('tr.jqplot-table-legend td').toggleClass('jqplot-series-hidden');

或者你可以触发所有元素的点击事件:

$('tr.jqplot-table-legend td').trigger('click');

推荐阅读