Jump to content

Adjusting bar size/number in bar chart


lorensewusu

Recommended Posts

I am using iReport to generate bar chart. However for some reports, if there is only one bar then it spreads and fills the whole report, is it possible to adjust the bar size if it is only one?  I have attached an example

 

Secondly, if the number of bars are so many say 150 bars, then they become unrecongizatble. Is there any way round it. i will be grateful to get help!!!

 

Lawrence

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

According to the documentation that comes with jfreechart which is used by iReport you may be able to dynamically control the bar width by using the maximumBarWidth attribute, you can use the methods of setMaximumBarWidth and getMaximumBarWidth.

I have created an attachment which includes the pdf that comes with JFreeCharts for your perusal. 

I do love JFreeChart, I just wish that I could understand JasperReports as well. 

Link to comment
Share on other sites

I just noticed your second question.

The chart will only output the information that you give it. 

My suggestion is to write a query that will limit the amount of data that you would give it.

SELECT *
  FROM (SELECT * FROM TABLE_NAME)
 WHERE ROWNUM < 10;

 

Link to comment
Share on other sites

  • 3 weeks later...

Hi,

After struggling with chart customizations I found out that the best way to work with charts is to generate the JFreechart outside the report and give it as a parameter. You have the advantage that you can have full customization of your chart and the generated chart may be used in your web pages adn in the reports.

The procedure is as follows.

1) Build a java class that generates the chart and returns a JFreeChart object.

2) Send the chart as a parameter:

        IndiChart chart = new IndiChart(selectedYear, chartStartYear, chartEndYear, chartTitle,
                chtType, frequency, chartResultsCount,
                "", chartRangeAxisLabel, dataSeriesNames, dataSeriesColors,
                chartTargetValues, chartResultValues);  --> Initialize de java class
        JFreeChart indiChart = chart.createChart(true);  --> Build the chart
        parameters.put("indicatorChart", new JCommonDrawableRenderer(indiChart)); --> put the chart as a parameter
 

3) in your report, define a parameter of type java.lang.object (lets say its named "indicatorChart")

4) include an Image object in your report and :

4.1) In the image expression enter:   (net.sf.jasperreports.engine.JRRenderable)$P{indicatorChart}

4.2) In the expression class enter:   net.sf.jasperreports.engine.JRRenderable

4.3) select the Scale Image property option that suits your needs.

 

By using this procedure I'm getting really good images!

Hope this helps you

Link to comment
Share on other sites

  • 1 month later...

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...