我在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;
}
答案 0 :(得分:3)
自Primefaces 5.1以来,解决方案(由链接上的jKick提供)发生了一些小变化。
在Primefaces 5.1之前你可以做到:
<p:lineChart extender="customExtender" value="..." />
从Primefaces 5.1开始,删除了图表组件以支持p:chart,现在需要在Java代码上设置extender属性:
LineChartModel lineChart = new LineChartModel();
lineChart.setExtender("customExtender");
这是你的扩展程序Javascript代码:
<script>
function customExtender () {
this.cfg.grid = {
background: '#FFF' //Set background to white
};
}
</script>
答案 1 :(得分:1)
选中此项:Similar question about changing jQplot graphs。图形配置中有一个名为background: '#fffdf6', // CSS color spec for background color of grid.
还有一个例子如何使用它。祝你好运。