mmmiller Posted February 16, 2011 Share Posted February 16, 2011 Hello,I have been struggling with what should be a simple barchart report. I hope someone can answer my questions:1. How do you align verticle bar columns with 90 degree labels? The middle bars/labels are aligned, but the outer ones are way off.2. How do you get the horizontal axis tick marks to show up? The verticle tick marks show up fine.3. How do you set a minimum width for each bar in the chart? There is plenty of white space that the bars are not using.Regards,MarkCode:<?xml version="1.0" encoding="UTF-8"?><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" pageWidth="792" pageHeight="1224" columnWidth="752" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <style name="Sans_Normal" isDefault="true" fontName="SansSerif" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/> <style name="Sans_Bold" fontName="SansSerif" fontSize="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false"/> <style name="Sans_Italic" fontName="SansSerif" fontSize="12" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false"/> <parameter name="reportHeader" class="java.lang.String"/> <parameter name="granularity" class="java.lang.String"/> <parameter name="columnName" class="java.lang.String"/> <parameter name="startDay" class="java.lang.String"/> <parameter name="endDay" class="java.lang.String"/> <field name="companyName" class="java.lang.String"/> <field name="totalHours" class="java.math.BigDecimal"/> <field name="nodeName" class="java.lang.String"/> <field name="avResourceName" class="java.lang.String"/> <field name="location" class="java.lang.String"/> <field name="sortField" class="java.lang.String"/> <sortField name="sortField"/> <variable name="summedHours" class="java.math.BigDecimal" resetType="Group" resetGroup="sortFieldGroup" calculation="Sum"> <variableExpression><![CDATA[$F{totalHours}]]></variableExpression> <initialValueExpression><![CDATA[new java.math.BigDecimal(0)]]></initialValueExpression> </variable> <variable name="sortFieldGroup_Index" class="java.lang.Integer" resetType="None"> <variableExpression><![CDATA[$V{sortFieldGroup_COUNT}]]></variableExpression> </variable> <variable name="maxSummedHours" class="java.math.BigDecimal" calculation="Highest"> <variableExpression><![CDATA[$V{summedHours}]]></variableExpression> <initialValueExpression><![CDATA[new java.math.BigDecimal(0)]]></initialValueExpression> </variable> <group name="sortFieldGroup"> <groupExpression><![CDATA[$F{sortField}]]></groupExpression> <groupFooter> <band height="20"> <textField> <reportElement isPrintRepeatedValues="false" x="0" y="0" width="130" height="20"/> <box> <pen lineWidth="0.5"/> </box> <textElement textAlignment="Right"/> <textFieldExpression class="java.lang.String"><![CDATA[$F{sortField}]]></textFieldExpression> </textField> <textField evaluationTime="Auto" pattern="###0.0"> <reportElement isPrintRepeatedValues="false" x="130" y="0" width="89" height="20"/> <box> <pen lineWidth="0.5"/> </box> <textElement textAlignment="Right"/> <textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{summedHours}.setScale(1,RoundingMode.HALF_EVEN)]]></textFieldExpression> </textField> </band> </groupFooter> </group> <background> <band splitType="Stretch"/> </background> <title> <band height="67" splitType="Stretch"> <textField isBlankWhenNull="true" bookmarkLevel="1"> <reportElement style="Sans_Normal" x="0" y="0" width="515" height="25"/> <textElement textAlignment="Center"> <font size="16"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$P{reportHeader}]]></textFieldExpression> <anchorNameExpression><![CDATA["Title"]]></anchorNameExpression> </textField> <textField isBlankWhenNull="true"> <reportElement style="Sans_Normal" x="0" y="45" width="515" height="20"/> <textElement textAlignment="Center"> <font size="14"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["From " + $P{startDay}+ " to " + $P{endDay}]]></textFieldExpression> </textField> <textField isBlankWhenNull="true"> <reportElement style="Sans_Normal" x="0" y="25" width="515" height="20"/> <textElement textAlignment="Center"> <font size="14"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Granularity = " + $P{granularity}]]></textFieldExpression> </textField> </band> </title> <pageHeader> <band height="20" splitType="Stretch"/> </pageHeader> <columnHeader> <band height="24"> <textField> <reportElement mode="Opaque" x="0" y="0" width="130" height="20" backcolor="#CCFFCC"/> <box> <pen lineWidth="0.5"/> </box> <textElement textAlignment="Right"> <font isBold="true"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$P{granularity}]]></textFieldExpression> </textField> <textField> <reportElement mode="Opaque" x="130" y="0" width="89" height="20" backcolor="#CCFFFF"/> <box> <pen lineWidth="0.5"/> </box> <textElement textAlignment="Right"> <font isBold="true"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA["Hours"]]></textFieldExpression> </textField> </band> </columnHeader> <columnFooter> <band height="20" splitType="Stretch"/> </columnFooter> <pageFooter> <band height="20" splitType="Stretch"/> </pageFooter> <summary> <band height="431" splitType="Prevent"> <barChart> <chart isShowLegend="true" evaluationTime="Report" customizerClass="com.hp.halo.reportingservice.jasperreports.BarChartCustomizer" renderType="draw" theme="default"> <reportElement x="0" y="20" width="558" height="398"/> <box> <pen lineWidth="0.5"/> <topPen lineWidth="0.5"/> <leftPen lineWidth="0.5"/> <bottomPen lineWidth="0.5"/> <rightPen lineWidth="0.5"/> </box> <chartTitle position="Top"> <titleExpression><![CDATA[$P{reportHeader}]]></titleExpression> </chartTitle> <chartSubtitle> <subtitleExpression><![CDATA["From " + $P{startDay}+ " to " + $P{endDay}]]></subtitleExpression> </chartSubtitle> <chartLegend position="Bottom"/> </chart> <categoryDataset> <categorySeries> <seriesExpression><![CDATA[$F{sortField}]]></seriesExpression> <categoryExpression><![CDATA[$F{sortField}]]></categoryExpression> <valueExpression><![CDATA[$V{summedHours}]]></valueExpression> <labelExpression><![CDATA[$V{summedHours}.setScale(1,RoundingMode.HALF_EVEN).toString()]]></labelExpression> </categorySeries> </categoryDataset> <barPlot isShowLabels="true" isShowTickMarks="true"> <plot labelRotation="90.0"/> <itemLabel color="#000000" backgroundColor="#FFFFFF"> <font isBold="false"/> </itemLabel> <categoryAxisLabelExpression><![CDATA[$P{granularity}]]></categoryAxisLabelExpression> <categoryAxisFormat labelRotation="90.0"> <axisFormat verticalTickLabels="true"> <labelFont/> <tickLabelFont/> </axisFormat> </categoryAxisFormat> <valueAxisLabelExpression><![CDATA["Hours"]]></valueAxisLabelExpression> <valueAxisFormat> <axisFormat verticalTickLabels="false"> <labelFont/> <tickLabelFont/> </axisFormat> </valueAxisFormat> <rangeAxisMaxValueExpression><![CDATA[$V{maxSummedHours}.add( $V{maxSummedHours}.multiply(new java.math.BigDecimal(0.1)) )]]></rangeAxisMaxValueExpression> </barPlot> </barChart> </band> </summary></jasperReport> Link to comment Share on other sites More sharing options...
szaharia Posted February 24, 2011 Share Posted February 24, 2011 Hi, I'm not sure which exactly is the problem, because I couldn't reproduce it. If possible, please post a screenshot here with the generated chart to see exactly what misalignment was produced. Visible tick marks were made available for category axis in the last JFreeChart 1.0.13 release. If you add this library to your app classpath and remove the older versions, the problem should be automatically solved. Bar width claculation depends on the axis length, the number of categories and the amount of separation space between categories. One can narrow down the unused space between categories in a customizer class, like below.Hope this helps,sandaCode:public void customize(JFreeChart chart, JRChart jasperChart){ CategoryPlot categoryPlot = (CategoryPlot)chart.getPlot(); categoryPlot.getDomainAxis().setCategoryMargin(0.05); // or any other valid percentual value} Link to comment Share on other sites More sharing options...
gcochard Posted March 8, 2011 Share Posted March 8, 2011 Hi,I see exactly what you mean and I provided a screenshot as requested.The behaviour is the following :When the series expression is repeated in the dataset for different category expression (even sorted by series expression) , the BAR does not get aligned with the label as it ould save some space for other bars??!!Strange!! Code:<?xml version="1.0" encoding="UTF-8"?><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Evaluation" language="groovy" pageWidth="1440" pageHeight="2160" columnWidth="1400" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true"> <property name="ireport.zoom" value="0.5"/> <property name="ireport.x" value="0"/> <property name="ireport.jasperserver.reportUnit" value="/COHERANS/PRODUCTION/REPORTS/Evaluation/Cloud_Report"/> <property name="ireport.jasperserver.url" value="http://iptr.coherans.com:8080/jasperserver/services/repository"/> <property name="ireport.y" value="0"/> <style name="Crosstab Data Text" hAlign="Center"/> <style name="table"> <box> <pen lineWidth="1.0" lineColor="#000000"/> </box> </style> <style name="table_TH" mode="Opaque" backcolor="#F0F8FF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> </box> </style> <style name="table_CH" mode="Opaque" backcolor="#BFE1FF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> </box> </style> <style name="table_TD" mode="Opaque" backcolor="#FFFFFF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> </box> </style> <style name="Heading 1" fontSize="16" isBold="true"/> <subDataset name="Evaluation"> <parameter name="Org_Name_Input" class="java.math.BigDecimal"> <defaultValueExpression><![CDATA[40]]></defaultValueExpression> </parameter> <parameter name="Choisir_le_niveau" class="java.lang.String"> <defaultValueExpression><![CDATA[3]]></defaultValueExpression> </parameter> <parameter name="Action_Id" class="java.lang.Long"> <defaultValueExpression><![CDATA[4]]></defaultValueExpression> </parameter> <parameter name="Level" class="java.lang.String"> <defaultValueExpression><![CDATA[2]]></defaultValueExpression> </parameter> <parameter name="AvgAction" class="java.lang.String" isForPrompting="false"> <defaultValueExpression><![CDATA[1.5]]></defaultValueExpression> </parameter> <queryString> <![CDATA[sELECTp_sk.name,eval_number,comp,avg(level_input) as avg_level,$P{AvgAction} as avgFROM dw_eval_fact skINNER JOIN skill p_sk ON sk.lft BETWEEN p_sk.lft AND p_sk.rgt AND p_sk.root_id = sk.root_idWHEREsk.level = $P{Choisir_le_niveau}andp_sk.level = $P{Level}andaction_id = $P{Action_Id}and (site_id = $P{Org_Name_Input} OR div_id = $P{Org_Name_Input} OR compte_id = $P{Org_Name_Input} OR groupe_id = $P{Org_Name_Input})GROUP BYeval_number, comp , p_sk.nameORDER BY comp , p_sk.name]]> </queryString> <field name="name" class="java.lang.String"/> <field name="eval_number" class="java.lang.String"/> <field name="comp" class="java.lang.String"/> <field name="avg_level" class="java.math.BigDecimal"/> <field name="avg" class="java.math.BigDecimal"/> </subDataset> <parameter name="Liste_stagiaire" class="java.lang.String"> <defaultValueExpression><![CDATA["OIGP.000052"]]></defaultValueExpression> </parameter> <parameter name="Level" class="java.lang.String"> <defaultValueExpression><![CDATA[2]]></defaultValueExpression> </parameter> <parameter name="Action_Id" class="java.lang.Long"> <defaultValueExpression><![CDATA[4]]></defaultValueExpression> </parameter> <parameter name="Time_Dim_Input" class="java.lang.String"> <defaultValueExpression><![CDATA[2]]></defaultValueExpression> </parameter> <parameter name="Org_Dim_Input" class="java.lang.Long"> <defaultValueExpression><![CDATA[0]]></defaultValueExpression> </parameter> <parameter name="Time_Chooser" class="java.util.Collection"/> <parameter name="Choisir_le_niveau" class="java.lang.String"> <defaultValueExpression><![CDATA[3]]></defaultValueExpression> </parameter> <parameter name="Org_Name_Input" class="java.math.BigDecimal"> <defaultValueExpression><![CDATA[40]]></defaultValueExpression> </parameter> <queryString> <![CDATA[sELECTeval_number,comp,avg(level_input) as avg_levelFROM dw_eval_fact skWHEREsk.level = 0andaction_id = $P{Action_Id}GROUP BYeval_number, compORDER BY comp]]> </queryString> <field name="eval_number" class="java.lang.String"/> <field name="comp" class="java.lang.String"/> <field name="avg_level" class="java.math.BigDecimal"/> <variable name="avg_level_1" class="java.math.BigDecimal" calculation="Average"> <variableExpression><![CDATA[$F{avg_level}]]></variableExpression> </variable> <background> <band splitType="Stretch"/> </background> <title> <band height="50" splitType="Stretch"/> </title> <pageHeader> <band splitType="Stretch"/> </pageHeader> <columnFooter> <band splitType="Stretch"/> </columnFooter> <pageFooter> <band splitType="Stretch"/> </pageFooter> <summary> <band height="2120" splitType="Stretch"> <multiAxisChart> <chart isShowLegend="true" renderType="image" theme="CoheransChart Theme V2"> <reportElement x="0" y="0" width="1400" height="586"/> <chartTitle/> <chartSubtitle/> <chartLegend position="Top"/> </chart> <multiAxisPlot> <plot labelRotation="0.0"/> <axis> <barChart> <chart isShowLegend="true" renderType="image" theme="CoheransChart Theme V2"> <reportElement x="0" y="0" width="0" height="0" backcolor="#FFFFFF"/> <chartTitle color="#000000"/> <chartSubtitle color="#000000"/> <chartLegend textColor="#000000" backgroundColor="#FFFFFF" position="Top"/> </chart> <categoryDataset> <dataset> <datasetRun subDataset="Evaluation"> <datasetParameter name="AvgAction"> <datasetParameterExpression><![CDATA[$V{avg_level_1}]]></datasetParameterExpression> </datasetParameter> <datasetParameter name="Action_Id"> <datasetParameterExpression><![CDATA[$P{Action_Id}]]></datasetParameterExpression> </datasetParameter> <datasetParameter name="Org_Name_Input"> <datasetParameterExpression><![CDATA[$P{Org_Name_Input}]]></datasetParameterExpression> </datasetParameter> <datasetParameter name="Choisir_le_niveau"> <datasetParameterExpression><![CDATA[$P{Choisir_le_niveau}]]></datasetParameterExpression> </datasetParameter> <datasetParameter name="Level"> <datasetParameterExpression><![CDATA[$P{Level}]]></datasetParameterExpression> </datasetParameter> </datasetRun> </dataset> <categorySeries> <seriesExpression><![CDATA[$F{name}]]></seriesExpression> <categoryExpression><![CDATA[$F{comp}]]></categoryExpression> <valueExpression><![CDATA[$F{avg_level}]]></valueExpression> <itemHyperlink> <hyperlinkTooltipExpression><![CDATA[$F{avg_level}]]></hyperlinkTooltipExpression> </itemHyperlink> </categorySeries> </categoryDataset> <barPlot isShowLabels="true" isShowTickLabels="true" isShowTickMarks="true"> <plot labelRotation="90.0"/> <itemLabel color="#000000" backgroundColor="#FFFFFF"/> <categoryAxisFormat labelRotation="90.0"> <axisFormat verticalTickLabels="true"> <labelFont/> <tickLabelFont> <font size="8"/> </tickLabelFont> </axisFormat> </categoryAxisFormat> <valueAxisFormat> <axisFormat verticalTickLabels="false"> <labelFont/> <tickLabelFont/> </axisFormat> </valueAxisFormat> <rangeAxisMinValueExpression><![CDATA[0]]></rangeAxisMinValueExpression> <rangeAxisMaxValueExpression><![CDATA[3]]></rangeAxisMaxValueExpression> </barPlot> </barChart> </axis> <axis> <lineChart> <chart isShowLegend="true" renderType="draw" theme="aegean"> <reportElement x="0" y="0" width="0" height="0" backcolor="#FFFFFF"/> <chartTitle color="#000000"/> <chartSubtitle color="#000000"/> <chartLegend textColor="#000000" backgroundColor="#FFFFFF" position="Top"/> </chart> <categoryDataset> <dataset> <datasetRun subDataset="Evaluation"> <datasetParameter name="AvgAction"> <datasetParameterExpression><![CDATA[$V{avg_level_1}]]></datasetParameterExpression> </datasetParameter> <datasetParameter name="Level"> <datasetParameterExpression><![CDATA[$P{Level}]]></datasetParameterExpression> </datasetParameter> <datasetParameter name="Action_Id"> <datasetParameterExpression><![CDATA[$P{Action_Id}]]></datasetParameterExpression> </datasetParameter> <datasetParameter name="Choisir_le_niveau"> <datasetParameterExpression><![CDATA[$P{Choisir_le_niveau}]]></datasetParameterExpression> </datasetParameter> <datasetParameter name="Org_Name_Input"> <datasetParameterExpression><![CDATA[$P{Org_Name_Input}]]></datasetParameterExpression> </datasetParameter> </datasetRun> </dataset> <categorySeries> <seriesExpression><![CDATA["Moyenne Générale"]]></seriesExpression> <categoryExpression><![CDATA[$F{comp}]]></categoryExpression> <valueExpression><![CDATA[$F{avg}]]></valueExpression> <itemHyperlink> <hyperlinkTooltipExpression><![CDATA[$F{avg_level}]]></hyperlinkTooltipExpression> </itemHyperlink> </categorySeries> </categoryDataset> <linePlot isShowLines="true" isShowShapes="false"> <plot labelRotation="90.0"/> <categoryAxisFormat labelRotation="90.0"> <axisFormat verticalTickLabels="true"> <labelFont/> <tickLabelFont/> </axisFormat> </categoryAxisFormat> <valueAxisFormat> <axisFormat verticalTickLabels="false"> <labelFont/> <tickLabelFont/> </axisFormat> </valueAxisFormat> <rangeAxisMinValueExpression><![CDATA[0]]></rangeAxisMinValueExpression> <rangeAxisMaxValueExpression><![CDATA[3]]></rangeAxisMaxValueExpression> </linePlot> </lineChart> </axis> </multiAxisPlot> </multiAxisChart> </band> </summary></jasperReport> Link to comment Share on other sites More sharing options...
szaharia Posted March 9, 2011 Share Posted March 9, 2011 Hi,Very strange, indeed. This is kind of difficult problem, and it might be entirely related to the JFreeChart engine, because JasperReports do not perform calculations on axis if no min or max values, or tick count properties are provided. In this case, the affected axis is the domain axis, and min/max values were set only for the range axis.In my opinion, there are 2 possibilities: the problem resides either in the specific chart theme (if it performs some calculations on axis), or in the JFreeChart engine itself.For specific JFreeChart issues there is a dedicated forum here.Hope this helps,sanda Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now