【问题标题】:How to show or hide Primefaces chart Legend independently when you have two charts in the same view?当您在同一视图中有两个图表时,如何独立显示或隐藏 Primefaces 图表图例?
【发布时间】:2017-11-08 15:50:24
【问题描述】:

我在同一页面中有 2 个图表。我想只在一个图表中显示图例,而不是两者,但我只有一个全局解决方案。那是我的 javascript 代码:

$.jqplot.preDrawHooks.push(function () {
this.legend.show = true;});

还有我的 xhtml:

<p:chart id="chart17" responsive="true" type="bar"  model="#{chart17Bean.barModel}"  />
<p:chart id="chart18" responsive="true" type="bar"  model="#{chart18Bean.barModel}" />

已编辑:我使用的是 Primefaces 6.1

【问题讨论】:

    标签: javascript jsf charts primefaces jqplot


    【解决方案1】:

    在页面上添加这个JS函数

    function removeLegend() 
    {
         this.cfg.legend = {
              show: false
         };
    }
    

    然后在你的托管 bean 中添加

    barModel.setExtender("removeLegend");
    

    barModel 是您想要隐藏图例的图表模型。

    【讨论】:

      【解决方案2】:

      Primefaces 8,Chart Js,你可以将图例显示设置为 false

      Legend legend = new Legend();
      legend.setDisplay(false);
      options.setLegend(legend);
      
      

      【讨论】:

        【解决方案3】:

        解决了我的问题

        yourChart.options = {
                  legend: {
                    display: false,
                   }
              };
        

        【讨论】:

        • “yourChart”从何而来?这在 PrimeFaces 中不起作用
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-01-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-22
        相关资源
        最近更新 更多