如何使用 PrimeFaces 在 tabView 中渲染图表
我需要在某种状态页面上显示大量图表。图表应分组在 tabView
和 accordionPanel
中。此设置适用于 PrimeFaces 2.2.1。由于新版本的某些功能(并且图表不再是 Flash),我正在尝试迁移到 PrimeFaces 3(目前为 3.0.M3)。
<p:tabView>
<p:tab title="One">
<p:pieChart value="#{myBean.myChartOne}" />
</p:tab>
<p:tab title="Two">
<p:pieChart value="#{myBean.myChartTwo}" />
</p:tab>
</p:tabView>
使用 PrimeFaces 3 时,图表不会显示。有一个错误报告描述了此问题并指出应该在 3.0 M4 中延迟加载图表。
更新:
我现在使用带有延迟加载图表的 PrimeFaces 3.0 M4 快照。它看起来像这样:
<p:tabView>
<p:tab>
<p:accordionPanel>
<p:tab title="All time">
<p:commandButton value="load chart" type="button" onclick="onTimeChartAll.init(); buttonOnTimeChartAll.disable();"
widgetVar="buttonOnTimeChartAll"/>
<p:pieChart value="#{myBean.onTimeChartAll}" lazy="true"
widgetVar="onTimeChartAll" />
</p:tab>
<p:tab title="30 Days">
<p:commandButton value="load chart" type="button" onclick="onTimeChart30Days.init();buttonOnTimeChart30Days.disable();"
widgetVar="buttonOnTimeChart30Days"/>
<p:pieChart value="#{myBean.onTimeChart30Days}" lazy="true" widgetVar="onTimeChart30Days" />
</p:tab>
</p:accordionPanel>
</p:tab>
[...] <!-- and so on -->
</p:tabView>
我可以打开一个选项卡并单击按钮来加载图表。现在我想找到一种解决方案,在打开选项卡时自动加载图表。有没有解决方案可以在打开选项卡时自动加载图表?对于 p:accordionPanel
和 p:tabView
有 onTabShow
属性,但我想我需要它来 p:tab< /代码>。或者是否有可能通过
onTabShow
和 var
处理当前打开选项卡的 widgetVar
?
I need to display a lot of charts on some kind of status page. The charts should be grouped in tabView
and accordionPanel
. This setup works nice with PrimeFaces 2.2.1. Because of some features of the new version (and because the charts are no longer Flash) I am trying to migrate to PrimeFaces 3 (3.0.M3 at the moment).
<p:tabView>
<p:tab title="One">
<p:pieChart value="#{myBean.myChartOne}" />
</p:tab>
<p:tab title="Two">
<p:pieChart value="#{myBean.myChartTwo}" />
</p:tab>
</p:tabView>
With PrimeFaces 3 the charts don't show up. There is a bug report describing this problem and stating that there should be lazy loading for charts in 3.0 M4.
Update:
I am now using PrimeFaces 3.0 M4-snapshot with lazy loading charts. It looks like this:
<p:tabView>
<p:tab>
<p:accordionPanel>
<p:tab title="All time">
<p:commandButton value="load chart" type="button" onclick="onTimeChartAll.init(); buttonOnTimeChartAll.disable();"
widgetVar="buttonOnTimeChartAll"/>
<p:pieChart value="#{myBean.onTimeChartAll}" lazy="true"
widgetVar="onTimeChartAll" />
</p:tab>
<p:tab title="30 Days">
<p:commandButton value="load chart" type="button" onclick="onTimeChart30Days.init();buttonOnTimeChart30Days.disable();"
widgetVar="buttonOnTimeChart30Days"/>
<p:pieChart value="#{myBean.onTimeChart30Days}" lazy="true" widgetVar="onTimeChart30Days" />
</p:tab>
</p:accordionPanel>
</p:tab>
[...] <!-- and so on -->
</p:tabView>
I can open a tab and click on the button to load the chart. Now I want to find a solution to automatically load the chart when a tab is opened. The Is there a solution to automatically load the chart, when the tab is opened? For p:accordionPanel
and p:tabView
there is the onTabShow
attribute, but I think I would need it for p:tab
. Or is there a possibility to address the widgetVar
of the currently opened tab via onTabShow
and var
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
primefaces 项目负责人刚刚写了一篇 博客文章 说这个问题应该在 3.0.M4 中修复:
The primefaces project lead just wrote a blog post saying that this should be fixed in 3.0.M4: