Reputation: 51
I have a chart in Primefaces5 and Works fine, but I need change background color using java code only, no jqplot code.
Default color is light but isn't White and my user wants White color.
Any suggestions will be greatly appreciated. Thanks!
Here my code (fragment):
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;
}
Upvotes: 1
Views: 4932
Reputation: 155
There’s a small change on the solution (provided by jKick on the link) since Primefaces 5.1.
Before Primefaces 5.1 you could do:
<p:lineChart extender="customExtender" value="..." />
From Primefaces 5.1 onwards, chart component was removed in favour of p:chart and extender property now needs to be set on your Java code:
LineChartModel lineChart = new LineChartModel();
lineChart.setExtender("customExtender");
And this is your extender Javascript code:
<script>
function customExtender () {
this.cfg.grid = {
background: '#FFF' //Set background to white
};
}
</script>
Upvotes: 4
Reputation: 561
Check this: Similar question about changing jQplot graphs. There is parametar in graph configuration called background: '#fffdf6', // CSS color spec for background color of grid.
Also there is example how to use it. Good luck.
Upvotes: 1