【问题标题】:Toggle pie chart series in p:chart在 p:chart 中切换饼图系列
【发布时间】:2016-11-09 21:15:29
【问题描述】:

我正在使用 Primefaces 5.3 并尝试允许用户通过单击相应的图例项来打开和关闭系列。

因为 primefaces 5.3 在 jqplot.txt 中不包含 EnhancedPieLegendRenderer,所以我在 resources/js 中手动添加了它并将其导入到我的项目中。我的扩展器的代码位于同一目录中名为 charts.js 的文件中。

在我的 .xhtml 文件中,我像这样引入文件

 <ui:composition template="/templates/template.xhtml">
   <ui:define name="body">
    <h:outputScript name="js/jqplot.pieRenderer.js"/>
    <h:outputScript name="js/extendedPieRenderer.js"/>
    <h:outputScript name="js/jqplot.enhancedPieLegendRenderer.js"/>
    <h:outputScript name="js/charts.js"/>

饼图本身的 xhtml 看起来像

<p:chart id="outboundLanChart" 
         type="pie" 
         model="#{foo.bar}"/>

底层 PieChartModel 对象或支持 bean 没有什么特别之处,一切都很好。在用户导航到页面时调用的 init 方法中,我设置了对象的扩展器 bar.setExtender("extnd");

在 charts.js 我有

function extnd() {

  this.cfg.seriesDefaults = {
    renderer: $.jqplot.PieRenderer
  }

  this.cfg.legend = {
    renderer: $.jqplot.EnhancedPieLegendRenderer,
    show: true,
    rendererOptions: {
        seriesToggle: 'normal',
        seriesToggleReplot: true
    }
  }

}

我知道扩展器正在工作,因为我的荧光笔配置完全符合我的预期(我没有包含那段代码,因为它与问题无关)。对this.cfg.legendconsole.log 检查表明它没有将EnhancedPieLegendRenderer 用于legend.renderer 属性。到目前为止,搜索 google、StackOverflow、primefaces 论坛以及各种文档和源代码都没有产生任何好的结果。 是否有可能让 primefaces 使用 EnhancedPieLegendRenderer 或者是否有另一种更合适的 Primefaces 方式允许用户在饼图上或饼图中切换系列?

更新:在 Kukeltje 的建议下,我包含了 pieRendererextendedPieRenderer 插件并相应地更新了我的 js 代码。这可能是一个问题,但不是问题,问题仍然存在。

【问题讨论】:

    标签: jsf primefaces jqplot


    【解决方案1】:

    通过一些关于“EnhancedPieLegendRenderer”的非常简单的谷歌搜索,我发现“EnhancedLegendRenderer”对于原生 jqplot 也不能​​正常工作:jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts。他们创建了您似乎正在使用的EnhancedPieLegendRenderer,但它需要与extendedPieRenderer 结合使用。由于您似乎没有使用后者,这是实际问题。

    【讨论】:

    • 感谢您的回答,我认为我在看一些明显的东西。我将它和饼图渲染器和扩展饼图渲染器插件包括在内,并更新了我的 js 代码,但问题仍然存在。
    • 我做到了。当我在 JFiddle 中测试时,我的设置工作正常。 jsfiddle.net/19vzL5h2/79
    • 然后检查jqplot版本不同,检查js加载顺序是否是probkem等
    【解决方案2】:

    显然extendedPieRendererenhancedPieLegendRenderer 不适用于任何版本的 jqplot Primefaces 5.3。

    获取最新版本并将我的脚本更改为

     <h:outputScript name="js/jqplot.1.0.9/jquery.jqplot.js"/>
     <h:outputScript name="js/jqplot.1.0.9/plugins/jqplot.pieRenderer.js"/>
     <h:outputScript name="js/jqplot.1.0.9/plugins/jqplot.enhancedPieLegendRenderer.js"/>
    

    修复了问题。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多