在Primefaces中动态生成条形图

在Primefaces中动态生成条形图

问题描述:

我正在使用Primefaces 4.0.我需要根据查询结果的数量来生成条形图.条形图的标题和颜色也应该能够使用查询结果为所有对象动态设置.条形图示例如下:-

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" />

在上面的条形图示例中,value属性将仅加载具有固定标题的1个类别模型.因此我一直在思考如何解决此问题.此外,我还需要为每个生成的条形图使用不同的颜色.

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.

查询结果可以是从0开始的任何数字(无数据).

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

解决方案是将p:barchart转换为p:datagrid.该数据网格将通过条形图列表加载. 进一步创建一个类类型为list的列表,该类类型包含barchart,title和color作为属性.这完全可以解决您的问题.

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.

解决方案:

<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.