我正在编写一份jasper报告,其中我正在创建一个条形图。对于单个条形,已创建单独的系列表达式。但在我的情况下,x轴和条纹上的标签没有正确对齐。
我的jrxml文件的一部分在这里提到:
<categoryDataset>
<categorySeries>
<seriesExpression><![CDATA["CalWORKS"]]></seriesExpression>
<categoryExpression><![CDATA["CalWORKS"]]></categoryExpression>
<valueExpression><![CDATA[$F{calworks_count}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Immediate Need CW"]]></seriesExpression>
<categoryExpression><![CDATA["Immediate Need CW"]]></categoryExpression>
<valueExpression><![CDATA[$F{calworks_immediate_need_count}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["CalFresh"]]></seriesExpression>
<categoryExpression><![CDATA["CalFresh"]]></categoryExpression>
<valueExpression><![CDATA[$F{calfresh_count}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Expedited CF"]]></seriesExpression>
<categoryExpression><![CDATA["Expedited CF"]]></categoryExpression>
<valueExpression><![CDATA[$F{calfresh_expedited_count}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Medi-Cal"]]></seriesExpression>
<categoryExpression><![CDATA["Medi-Cal"]]></categoryExpression>
<valueExpression><![CDATA[$F{medical_count}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["Immediate Medi-Cal"]]></seriesExpression>
<categoryExpression><![CDATA["Immediate Medi-Cal"]]></categoryExpression>
<valueExpression><![CDATA[$F{medical_immediate_need_count}]]></valueExpression>
</categorySeries>
</categoryDataset>
我也在使用这里给出的定制器:
public void customize(JFreeChart chart, JRChart jasperChart) {
CategoryPlot plot = (CategoryPlot)chart.getPlot();
BarRenderer barRenderer = (BarRenderer)plot.getRenderer();
Font font = new Font("Calibri", Font.BOLD, 12);
plot.getRenderer().setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
barRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
barRenderer.setBaseItemLabelFont(font);
barRenderer.setBaseItemLabelsVisible(true);
plot.getDomainAxis().setMaximumCategoryLabelLines(2);
plot.getRangeAxis().setUpperMargin(plot.getRangeAxis().getUpperMargin() + 0.1);
barRenderer.setItemLabelAnchorOffset(5.0d);
//barRenderer.setMaximumBarWidth(0.9f);
barRenderer.setItemMargin(0.0f);
}
我尝试调整barWidth值,但它不起作用。我还制作了分为两行的标签,这也没有用。有没有办法实现这个目标?
此外,我无法增加条的宽度。使用定制器我们如何实现这一目标?
答案 0 :(得分:1)
这是这篇文章的准复制品:Align bars with bar labels in Jfreechart
在您的情况下,当然,解决方案是重新格式化您的xml文件,只留下一个系列(六个类别中):
<categoryDataset>
<categorySeries>
<seriesExpression><![CDATA["series1"]]></seriesExpression>
<categoryExpression><![CDATA["CalWORKS"]]></categoryExpression>
<valueExpression><![CDATA[$F{calworks_count}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["series1"]]></seriesExpression>
<categoryExpression><![CDATA["Immediate Need CW"]]></categoryExpression>
<valueExpression><![CDATA[$F{calworks_immediate_need_count}]]></valueExpression>
</categorySeries>
...