Dynamic generation of Bar Charts in Primefaces

房东的猫 提交于 2019-12-22 13:58:51

问题


I am using Primefaces 4.0. I have a requirement to generate Bar charts depending on the number of results of a query.The Title and color of Bar charts should also be able to set dynamically for all using the query results. Example of bar chart as follows:-

<p:barChart id="barStats"
        value="#{Bean.categoryModel}" legendPosition="ne"
        style="width:300px;height:250px;"
        title="Break Down(Barchart)" barMargin="10" min="0"
        barPadding="10" max="40" animate="true" />

In the above example of bar chart the value attribute will load only 1 category model with fixed title.So i was figuring out how can i solve this problem. Further i also need a different color for each bar chart generated.

The query results could be any number from starting from 0(no data).


回答1:


The solution is to use p:barchart into a p:datagrid. This datagrid will be loaded through a list of barcharts. Further create the list with a class type which contains barchart,title and color as attributes.And this perfectly solves your problem.

Solution:

<p:dataGrid id="chartdataGrid" var="list" value="#{Bean.chartList}" columns="2" style="border:none;">

  <p:barChart 
        value="#{list.chart}" title="#{list.title}"
        style="height:190px;width:350px" 
        barMargin="20" min="0" barPadding="10" animate="true" seriesColors="#{list.barColor}" />

</p:dataGrid>

if any you need any further clarification for this problem and its detail solution then i will love to provide it.

Hope my Solution helps you.



来源:https://stackoverflow.com/questions/23999328/dynamic-generation-of-bar-charts-in-primefaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!