gpt4 book ai didi

java - Primefaces5 如何更改图表中的背景颜色(纯 java,无 jqplot)

转载 作者:行者123 更新时间:2023-11-29 03:13:31 26 4
gpt4 key购买 nike

我在 Primefaces5 中有一个图表并且工作正常,但我需要仅使用 java 代码更改背景颜色,不需要 jqplot 代码。

enter image description here

默认颜色是浅色,但不是白色,我的用户想要白色。

任何建议将不胜感激。谢谢!

这是我的代码(片段):

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>

关于java - Primefaces5 如何更改图表中的背景颜色(纯 java,无 jqplot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27970106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com