Jump to content

Recommended Posts

Posted

Hello, 

I created a StackedBar item and want to eliminate the space between the bars. I wrote the following customerize, but the bars are sill spaced, any idea ?

thanks in advnace.

 

[/code]
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.engine.JRChart;

import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.*; 

public class CustomizeBarChart extends JRAbstractChartCustomizer {
@Override    
public void customize(JFreeChart chart, JRChart jasperChart) { 
CategoryPlot categoryPlot = chart.getCategoryPlot();
StackedBarRenderer  renderer = (StackedBarRenderer) categoryPlot.getRenderer();  
chart.setTitle("Hello");   
renderer.setItemMargin(0.0);     }}

 

 

update:

Here is the scala version of the same code: 

import net.sf.jasperreports.engine.JRAbstractChartCustomizer;

import net.sf.jasperreports.engine.JRChart;
 
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BarRenderer;
 
class CustomizeBarChart extends JRAbstractChartCustomizer{
  
def customize(chart: JFreeChart ,  jasperChart:JRChart) =
{
 
val categoryPlot: CategoryPlot  = chart.getCategoryPlot()
 
val renderer: BarRenderer  = categoryPlot.getRenderer().asInstanceOf[barRenderer]
 
//Spaces between bars
renderer.setItemMargin(0.05f)
 
categoryPlot.getDomainAxis().setCategoryMargin(0.05f)
chart.setTitle("Hello From scala")
 
    }
  
}

 

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

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