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

Dynamically change the Bar Chart width


pumi_hasi

Recommended Posts

Hi,

  I used iReport and jasper to create a bar chart which displays some graphical information depending on the user selection in the system.The number of bars in the bar chart get changed depending on the query results at each time.Being the defined chart width is a fixed value the bar width in the chart get changed each time.When there is only one bar in the chart, that bar is taking the full width from the chart width. So I want to dynamically change the chart width depending on the sql query results, or is there any way to keep the individual bar width fixed?

Thank You

Hasini

 

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Hi Hasini,

 

Even I had this problem previously in reports. I overcomed this issue by using Customizer class to customize the graph.

 

You need to know about the JFreeChart API to do this.

 

There is a sample delivered with the JasperReports distribution to demonstrate the customization. check the demo/samples folder in the JasperReports distribution.

 

DNV Srikanth

Link to comment
Share on other sites

  • 1 year later...

First the charting package does not allow you to set an absolute width. The best you can do is set a relative percentage width with respect to the total width of your chart.

To do this you have to create a customizer class as dnvsrikanth suggested.

In the customize method put the following code

if(jasperChart.getChartType() == JRChart.CHART_TYPE_BAR) {

                       

BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();

 

//Set maximum bar width

renderer.setMaximumBarWidth(0.10);

           

}

 

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 months later...
  • 5 years 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...