如何在PrimeFaces中更改Bar Charts Legend的位置?

时间:2015-01-11 04:25:25

标签: jsf primefaces charts

我正在使用PrimeFaces条形图在JSF中开发Web应用程序。我想改变传奇的位置。我在他们使用的帖子中验证了Primefaces: Charts and Legend position

<p:barChart id="stackedKWH"
            value="#{kwhSalesBeanManager.kwhSalesChart}"
            legendPosition="e" style="height:300px;width:800px"
            title="kWh Sales by Type"
            stacked="true"
            barMargin="10"
            min="0"
            max="125000000"/>

但在primeface 5.1中没有<p:barchart/>

<p:chart type="bar" model="#{chartView.barModel}" style="height:300px"/>

我的输出看起来像,

enter image description here

预期产出:

enter image description here

我怎样才能做到这一点?有人建议我使用正确的方法吗?

2 个答案:

答案 0 :(得分:5)

您可以在bean上执行此操作:

BarChartModel model = new BarChartModel();
model.setLegendPosition("e");
model.setLegendPlacement(LegendPlacement.OUTSIDEGRID);

答案 1 :(得分:1)

你仍然可以使用model.setLegendPosition(&#34; w&#34;);在你的豆子里。 如果需要更具体的控件,可以修改图例表的css。该类称为table.jqplot-table-legend。

这样的事情:

XHTML:

   <p:chart styleClass="barChartStyleClass" type="bar" widgetVar="barChart" model="#{playgroundController.barModel}" style="width:400px;height:300px">

    </p:chart> 

CSS:

.barChartStyleClass table.jqplot-table-legend {
    top:50px !important;
    right:50px !important;
    //more css here
}

也许你可以让它在没有!重要的情况下工作,但我没有运气。但我仍然希望它有所帮助:)