![](/img/trans.png)
[英]How to change color in primefaces bar chart for every column of the same series?
[英]Primefaces5 How to change background color in chart (pure java, no jqplot)
我在Primefaces5中有一张图表并且工作正常,但是我只需要使用Java代码更改背景颜色,而无需jqplot代码。
默认颜色是浅色,但不是白色,我的用户想要白色。
任何建议将不胜感激。 谢谢!
这是我的代码(片段):
private void createBarModelsN()
{
graphic2 = initBarModelN();
graphic2.setTitle("");
// Indica la posicion del cuadrito con la leyenda de la serie
// null indica que no mostrara el cuadrito
graphic2.setLegendPosition( null );
graphic2.setShadow( false );
graphic2.setStacked( isStacked );
graphic2.setAnimate( true );
graphic2.setBarMargin( 20 );
graphic2.setBarPadding( 0 );
String strSeriesColor = "";
for(int i=0; i < numeroDeSeries; i++ )
{
strSeriesColor += arregloColoresDefault[i];
if( i < numeroDeSeries - 1 )
{
strSeriesColor += ",";
}
}
graphic2.setSeriesColors( strSeriesColor );
Axis xAxis = graphic2.getAxis(AxisType.X);
Axis yAxis = graphic2.getAxis(AxisType.Y);
// Para graficar porcentajes se requiere que el eje Y sea de 0 a 100
yAxis.setLabel( labelEjeY );
yAxis.setMax(100);
yAxis.setMin(0);
yAxis.setTickAngle( 0 );
yAxis.setTickCount( 11 );
yAxis.setTickInterval( "10" );
xAxis.setMin( getValorMinX());
xAxis.setMax( getValorMaxX());
xAxis.setTickInterval( "1" );
xAxis.setLabel( labelEjeX );
}
private BarChartModel initBarModelN()
{
BarChartModel model = new BarChartModel();
// Hago el for para obtener cada una de las series
for( int i=0; i < series.size(); i++ )
{
ChartSeries serieX = new ChartSeries();
int indexArreglo = 0;
for( int j=getValorMinX(); j <= getValorMaxX(); j++ )
{
if( arregloTempo != null && listNSeries != null && listNSeries.size() >= 1
&&
arregloTempo.length == ((ArrayList<Integer>)listNSeries.get(i)).size()
)
{
int valorX = ((ArrayList<Integer>)listNSeries.get(i)).get( indexArreglo );
int valorXTotal = arregloTempo[ indexArreglo ];
float valorY = 0.0f;
if( valorXTotal != 0 )
{
valorY = (valorX / (valorXTotal + 0.0f) ) * 100;
}
serieX.set( j , valorY );
}
indexArreglo++;
}
model.addSeries(serieX);
}
return model;
}
自从Primefaces 5.1以来,解决方案有很小的变化(由链接上的jKick提供)。
在Primefaces 5.1之前,您可以执行以下操作:
<p:lineChart extender="customExtender" value="..." />
从Primefaces 5.1起,图表组件被删除,取而代之的是p:chart,现在需要在Java代码上设置扩展器属性:
LineChartModel lineChart = new LineChartModel();
lineChart.setExtender("customExtender");
这是您的扩展程序Javascript代码:
<script>
function customExtender () {
this.cfg.grid = {
background: '#FFF' //Set background to white
};
}
</script>
检查一下: 关于更改jQplot图的类似问题 。 在图形配置中有一个称为background: '#fffdf6', // CSS color spec for background color of grid.
还有示例如何使用它。 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.