Jump to content
We've recently updated our Privacy Statement, available here ×

3D Bar Chart


chr15athome

Recommended Posts

Hi,

I have a 3D bar chart that displays values from 0-70%. Most of the values are between 0-10% maybe 1 or 2 are upto 70%. Is there anyway of having the scale alternate to make the smaller values look more significant because most of them actually are significant to our client but look insignificant on the chart.

Thanks

Chris

Code:
																																																																																		$F{statisticType}						$F{alternativeDescription}						$V{PERCENTAGE}																																																																																															"Percentage (%)"																																											
Link to comment
Share on other sites

  • Replies 12
  • Created
  • Last Reply

Top Posters In This Topic

<bar3DChart>
    <chart isShowLegend="false" evaluationTime="Report" customizerClass="chartcustomizer.class">
     <reportElement key="element-1" stretchType="RelativeToBandHeight" x="3" y="26" width="580" height="204"/>
     <box>
      <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
      <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
      <bottomPen lineWidth="0.0" lineColor="#000000"/>
      <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
     </box>
     <chartTitle/>
     <chartSubtitle/>
     <chartLegend/>
    </chart>
    <categoryDataset>
     <dataset resetType="None"/>
     <categorySeries>
      <seriesExpression><![CDATA[$F{statisticType}]]></seriesExpression>
      <categoryExpression><![CDATA[$F{alternativeDescription}]]></categoryExpression>
      <valueExpression><![CDATA[$V{PERCENTAGE}]]></valueExpression>
      <itemHyperlink/>
     </categorySeries>
    </categoryDataset>
    <bar3DPlot isShowLabels="true">
     <plot backcolor="#FFFFFF" labelRotation="30.0"/>
     <categoryAxisFormat>
      <axisFormat>
       <labelFont>
        <font fontName="SansSerif" size="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
       </labelFont>
       <tickLabelFont>
        <font fontName="SansSerif" size="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfFontName="Helvetica" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
       </tickLabelFont>
      </axisFormat>
     </categoryAxisFormat>
     <valueAxisLabelExpression><![CDATA["Percentage (%)"]]></valueAxisLabelExpression>
     <valueAxisFormat>
      <axisFormat tickLabelMask="">
       <labelFont/>
       <tickLabelFont/>
      </axisFormat>
     </valueAxisFormat>
    </bar3DPlot>
   </bar3DChart>

Link to comment
Share on other sites

Hi Lucian,

 

Do you have any examples of how this can be done or a guide?

I have had a quick Google on chart customizers but not much help is available.

 

Do I write the customizer to extend JRAbstractChartCustomizer?

 

Do I have to create the chart sparately and send it as an object?

 

 

Thanks

 

Chris

 

Link to comment
Share on other sites

Hi Lucian,

I managed to figure the chart customizer out.

I just need to increase the bar width so that I can display the value of the bars percentage.

My code so far:-

 

Code:
public void customize(JFreeChart chart, JRChart jrChart) {                        final CategoryAxis categoryAxis = new CategoryAxis("Category");            this.chart = chart;                                             LogarithmicAxis logScale = new LogarithmicAxis("Percentage (%)");                        logScale.setStrictValuesFlag(false);            logScale.setRange(0.00, 100.0);            logScale.setTickLabelsVisible(true);                        chart.getCategoryPlot().setRangeAxis(logScale);            categoryAxis.setUpperMargin(0.5);                   }
Link to comment
Share on other sites

  • 2 weeks later...

Chris, Lucian,

 

I also need to implement log-scale plotting.  I am okay with writing my own Chart Customizer.  However, I don't know how to bind my Chart Customerizer to a report.  I am using iReport and JasperServer.  I have read the Ultimate Guide for both iReport and JasperReports, but could not an the answer.

 

Thanks!

Link to comment
Share on other sites

Chris, Lucien,

 

Oh now I now find a chart field called "Customizer Class"  I guess that is how I bind the chart to the customizer.

 

I am doing this with the X-Axis of a scatter plot.  I am not too familiar with JFreeChart.  Can you tell me how can I adopt Chris's code so that it would work with X-axis of a scatter plot?

 

Thanks a lot!

 

 

Link to comment
Share on other sites

Hi,

 

Using the following code, I made some progress.  The chart was rendered with the X-axis in log scale.  However, no data were plotted on the chart.

 

I saw that the Y-axis has been scaled to some meaningful scale meaning that the report had seen the correct data.  It just did not plot them on the chart?

 

Any idea?

Code:
package com.company;import org.jfree.chart.JFreeChart;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.axis.LogarithmicAxis;import net.sf.jasperreports.engine.JRAbstractChartCustomizer;import net.sf.jasperreports.engine.JRChart;public class MyChartCustomizerLogXAxis extends JRAbstractChartCustomizer {	JFreeChart chart;		public void customize(JFreeChart chart, JRChart jrChart) {                this.chart = chart;                                     LogarithmicAxis logScale = new LogarithmicAxis("Orig_Bytes (Log Scale)");                logScale.setStrictValuesFlag(true);        logScale.setRange(0.00, 10.0);        logScale.setTickLabelsVisible(true);                chart.getXYPlot().setDomainAxis(logScale); // No data plotted           }}
Link to comment
Share on other sites

Okay I found the problem.  It was my setRange() line that set a wrong range (should use values before taking the logarithm but not after taking the logarithm)

 

        logScale.setRange(0.00, 10.0); // <--- the range was wrongAfter I commented out the line (using auto range), the chart plots correctly.  Thanks you everyone!

 

Link to comment
Share on other sites

Hi Here is the code I ended up using:-

Does anyone know how to change the bar widths in the code below?

Thanks

Chris

Code:
public void customize(JFreeChart chart, JRChart jrChart) {                        final CategoryAxis categoryAxis = new CategoryAxis("Category");            final ValueAxis valueAxis = new LogarithmicAxis("Percentage (%)");            this.chart = chart;                                             LogarithmicAxis logScale = new LogarithmicAxis("Percentage (%)");            //            CategoryPlot plot = null;//            NumberAxis axis = new LogarithmicAxis("Percentage"); //            plot.setRangeAxis(axis);//                        logScale.setStrictValuesFlag(false);            logScale.setRange(0.00, 100.0);            logScale.setAutoTickUnitSelection(true);            //logScale.                                    //logScale.autoAdjustRange();            chart.getCategoryPlot().setRangeAxis(logScale);            categoryAxis.setUpperMargin(0.5);                        //plot.setRangeAxis(logScale);        }
Link to comment
Share on other sites

chr15athome
Wrote:

Also I would like to show more values on the vlue axis maybe 0,10,50,100. Is this possible? Thanks Chris

I'm not sure about that, try searching the JFreeChart forums to see whether there is anything about this.

Regards,

Lucian

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...