我需要你的帮助来理解一个非常奇怪的素数水平条行为。
我想做的是绘制一个带有素数面的水平条。
以下是我从postgresql数据库表中获取的所有数据:
有关以下说明,请参阅此horbarchart图像:
如果我从我的数据库中只获得前五个银行,那一切都没问题! (1)
如果我试图得到并显示所有银行的灾难发生:(只显示八个银行并且价值被转移。(2)
最后,如果我尝试获取并显示最后四个库,则只显示两个错误的值。 (3)
显然,我检查了调试器的IDE是否正确填充了每个图表系列并且所有内容都以非常正确的方式构建。
这是我的(hibernate)类,它从db获取数据:
public class ChartRequestTypeJPA {
static final transient Logger LOGGER = LogManager.getLogger(ChartRequestTypeJPA.class.getName());
static final transient ResourceBundle BUNDLE = FacesContext.getCurrentInstance().getApplication().getResourceBundle(FacesContext.getCurrentInstance(), "txt");
public List<ChartRequestType> getAll(TimeInterval step) throws Exception {
Session session = null;
try {
session = HibernateUtil.getSessionFactory().openSession();
Criteria criteria = session
.createCriteria(ChartRequestType.class)
.add(Restrictions.eq("pk.step", step.getDescr()));
List<ChartRequestType> result = criteria.list();
return result;
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("Error getting chart request type" + e.getMessage());
throw new DMLException(BUNDLE.getString("message.noDataFound"));
} finally {
if (session != null) {
session.close();
}
}
}
}
这是我设置条形图模型的类:
@ManagedBean
@RequestScoped
public class Chart11RequestTypeView {
private HorizontalBarChartModel chartRequestTypeModel;
private void createHorizontalBarModel() {
chartRequestTypeModel = new HorizontalBarChartModel();
ChartSeries informazioni = new ChartSeries();
ChartSeries anomalia = new ChartSeries();
ChartSeries rio = new ChartSeries();
// Valori percentuali della singola banca sul totale letto da oracle
informazioni.setLabel(TXT.getString("uilabel.chart11.informazioni"));
anomalia.setLabel(TXT.getString("uilabel.chart11.anomalia"));
rio.setLabel(TXT.getString("uilabel.chart11.rio"));
int size = chartRequestType.size();
for (int i = 0; i < size; i++) {
String tipologia = chartRequestType.get(i).getPk().getTipologia();
String bankName = chartRequestType.get(i).getPk().getName();
int tickNumb = chartRequestType.get(i).getTicketnumber();
switch(tipologia){
case "Anomalia":{
anomalia.set(bankName, (int) tickNumb);
break;
}
case "Informazioni":{
informazioni.set(bankName, (int) tickNumb);
break;
}
case "Richiesta Operativa":{
rio.set(bankName, (int)tickNumb);
break;
}
}
if(chartRequestType.get(i).getPk().getTipologia().equals("Informazioni")){
informazioni.set(chartRequestType.get(i).getPk().getName(), chartRequestType.get(i).getTicketnumber());
}
if(chartRequestType.get(i).getPk().getTipologia().equals("Anomalia")){
anomalia.set(chartRequestType.get(i).getPk().getName(), chartRequestType.get(i).getTicketnumber());
}
if(chartRequestType.get(i).getPk().getTipologia().equals("Richiesta Operativa")){
rio.set(chartRequestType.get(i).getPk().getName(), chartRequestType.get(i).getTicketnumber());
}
}
chartRequestTypeModel.setSeriesColors("999999,666666,333333");
chartRequestTypeModel.setTitle(TXT.getString("uilabel.chart11.title"));
chartRequestTypeModel.addSeries(anomalia);
chartRequestTypeModel.addSeries(informazioni);
chartRequestTypeModel.addSeries(rio);
Axis xAxis = chartRequestTypeModel.getAxis(AxisType.X);
xAxis.setLabel(TXT.getString("uilabel.chart11.number"));
xAxis.setMin(0);
xAxis.setTickAngle(40);
xAxis.setTickFormat("%d");
chartRequestTypeModel.setExtender("chartRequestTypeExtender");
// horizontalBarModel.setShowPointLabels(true); qui non serve, sta nell'extender
}
}
最后,这是我的xhtml:
<p:panel style="text-align: center; width:100%; border: 0px;">
<p:panelGrid id="pchart11" columns="1" style="text-align: center; margin-bottom:10px; width: 100%; height:600px;">
<p:row>
<p:chart type="bar" model="#{chart11RequestTypeView.chartRequestTypeModel}" style="height:600px;" />
</p:row>
</p:panelGrid>
</p:panel>
<script language="javascript" type="text/javascript">
function chartRequestTypeExtender() {
this.cfg.sortData = true; // forse superfluo
this.cfg.legend = {
show: true,
location: 'e',
placement: 'insideGrid'
};
this.cfg.grid = {
background: 'transparent',
gridLineColor: '#D0D0FF',
drawBorder: false
};
this.cfg.seriesDefaults = {
renderer:$.jqplot.BarRenderer,
// Show point labels to the right ('e'ast) of each bar.
// edgeTolerance of -15 allows labels flow outside the grid
// up to 15 pixels. If they flow out more than that, they
// will be hidden.
pointLabels: { show: true, location: 'e', edgeTolerance: -15 },
// Rotate the bar shadow as if bar is lit from top right.
shadowAngle: 135,
// Here's where we tell the chart it is oriented horizontally.
rendererOptions: {
barDirection: 'horizontal'
}
};
this.cfg.highlighter = {
show: true,
tooltipAxes: 'x', // da usare anche in altri chart, evita l'ambiguita dei tootips tipo 3,7 inteso come 3.7 anzichè valore 7 per il punto 3
useAxesFormatters: false,
tooltipFormatString: "%i"};
}
</script>
</html>
任何人都可以帮助我吗? 非常感谢你的聆听
答案 0 :(得分:1)
解决!
Primefaces条形图需要为每个ChartSeries设置相同数量的值才能正确格式化它们。我为每个银行填充了我的三个系列,其中包含不同数量的值;这就是问题!
因此,请注意使用相同数量的值填充每个ChartSeries。
Enojoy! :)