Jsf 2 p:图表栏';图表系列未同步
我一直在研究PrimeFaces条形图模型,它现在让我很紧张,我只是不知道它是如何设置图表系列值的。预期的结果应该是,一个为abc打开,一个为xyz关闭,但它显示一个为xyz打开,一个为xyz关闭,abc被忽略。如果我改变了Jsf 2 p:图表栏';图表系列未同步,jsf-2,primefaces,bar-chart,jqplot,Jsf 2,Primefaces,Bar Chart,Jqplot,我一直在研究PrimeFaces条形图模型,它现在让我很紧张,我只是不知道它是如何设置图表系列值的。预期的结果应该是,一个为abc打开,一个为xyz关闭,但它显示一个为xyz打开,一个为xyz关闭,abc被忽略。如果我改变了 barModel.addSeries(关闭); barModel.addSeries(开放) 到 barModel.addSeries(打开); barModel.addSeries(关闭) 然后显示一个打开和一个关闭,仅用于abc,而不是xyz 这是我的getBarMod
barModel.addSeries(关闭);
barModel.addSeries(开放)代码>
到
barModel.addSeries(打开);
barModel.addSeries(关闭)代码>
然后显示一个打开和一个关闭,仅用于abc,而不是xyz
这是我的getBarModel()第一步
public BarChartModel getBarModel() {
barModel=new BarChartModel();
ChartSeries open = new ChartSeries();
open.setLabel("OPEN");
ChartSeries close = new ChartSeries();
close.setLabel("Close");
open.set("abc", 1);
close.set("xyz", 1);
barModel.addSeries(close);
barModel.addSeries(open);
barModel.setMouseoverHighlight(false);
barModel.setShowPointLabels(false);
barModel.setTitle("Incident_application");
barModel.setLegendPosition("ne");
barModel.setShowDatatip(false);
barModel.setShowPointLabels(true);
barModel.setExtender("chartExtender");
barModel.setSeriesColors("A2CC39,1B75BA");
Axis xAxis = barModel.getAxis(AxisType.X);
xAxis.setLabel("Applications");
barModel.setAnimate(true);
Axis yAxis = barModel.getAxis(AxisType.Y);
yAxis.setLabel("No. of Incident");
yAxis.setMin(0);
yAxis.setMax(20);
yAxis.setTickInterval("10");
return barModel;
}
这里是xhtml
我仍然得到奇怪的结果,即。
xyz为1打开和1关闭,xyz为0打开和0关闭。唯一的解决方案是,作为开发人员,确保所有系列包含所有键,并填充您没有的键,并确保所有系列中的所有键顺序相同
这样做的原因是只有您知道真正的顺序(这就是为什么在本系列中使用LinkedHashMap
)。jQplot或PrimeFaces无法知道这一点。例如,如果第一个系列遗漏了一个键,并且该系列被用作迭代的“主要”,那么遗漏的键将放在哪里。如果在第6位,两人都有一把不在另一组中的钥匙,那么应该先取哪一把?jqPlot或PrimeFaces无法知道。作为开发人员,您应该通过将所有键放在所有系列中来确保它是明确的。您需要为每个集合/系列为每个键指定一个值。因此,还要添加open.set(“xyz”,0);关闭。设置(“abc”,0)代码>(可能“null”适用于)。或者,这可能需要通过扩展器在jqplot级别上进行配置,因为动态数据太复杂了。为什么?钥匙是以某种方式“有序”的吗?还是订单相关?将钥匙按正确顺序组合在一组中是唯一的“挑战”。然后在该集合中添加,然后循环,并在其他集合中添加缺少的集合应该不会太困难。PF或jqPlot无法为您解决此问题。他们无法知道这两个集合中的哪一个包含正确的顺序。假设集合1以“a$”开头,集合2以“a$”开头,哪一个应该先出现?根据“字符串”订购,但如果“xyz”应该在“abc”之前,该怎么办?如果我尝试这样做,请打开。设置(“abc”,1);打开。设置(“xyz”,0);关闭。设置(“xyz”,1);关闭。设置(“abc”,0);条形图显示奇怪的结果,请检查编辑这是一个LinkedHashMap
(检查源代码),因此顺序是相关的。在两个设置中按相同的顺序设置。完全正确,这必须是唯一的情况。我会尝试一下,然后回来。
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
<h:outputScript library="primefaces" name="jquery/jquery-plugins.js" target="head" />
<style type="text/css">
table.jqplot-table-legend {
border: none;
font-size: x-large;
}
div.jqplot-table-legend-swatch
{
width: 2vw;
height: 2vh;
}
div.jqplot-gridData{
display:none;
}
div.jqplot-xaxis-tick{
font-weight:bold !important;
}
.jqplot-axis.jqplot-xaxis{
font-weight:bold;
}
.jqplot-point-label {
font-size: 300%;
color: black;
font-weight: bold;
}
.jqplot-target{
color:black !important;
}
</style>
<script>
function chartExtender() {
this.cfg.grid = {
background: 'transparent',
gridLineColor: '#303030',
drawBorder: false,
};
}
</script>
<h:form id="barChart">
<p:chart id="bar" type="bar" model="#{incidentBarChartController.barModel}" />
<p:poll interval="10" global="false" update="barChart"/>
</h:form>
</h:body>
open.set("abc", 1);
open.set("xyz",0);
close.set("xyz", 1);
close.set("abc", 0);