Problems reusing ChartFactory.createStackedBarChart(...)

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rhobit
Posts: 9
Joined: Wed Apr 02, 2014 8:43 am
antibot: No, of course not.

Problems reusing ChartFactory.createStackedBarChart(...)

Post by rhobit » Sun Apr 06, 2014 9:01 am

I tried to override createStackedBarChart(...) by implementing my own version in another class. I want to use my own version of a CategoryPlot. But as soon as I use the identical code from ChartFactory including the original CategoryPlot (as below) my chart-background changes to grey with horizontal dotted lines.

Code: Select all

public class ChartFactoryExtension {

	public static JFreeChart createStackedBarChart(String title,
			 String domainAxisLabel,
			 String rangeAxisLabel,
			 CategoryDataset dataset,
			 PlotOrientation orientation,
			 boolean legend,
			 boolean tooltips,
			 boolean urls) {
			 
			 if (orientation == null) {
			 throw new IllegalArgumentException("Null 'orientation' argument.");
			 }
			 
			 CategoryAxis categoryAxis = new CategoryAxis(domainAxisLabel);
			 ValueAxis valueAxis = new NumberAxis(rangeAxisLabel);
			 
			 StackedBarRenderer renderer = new StackedBarRenderer();
			 if (tooltips) {
			 renderer.setBaseToolTipGenerator(
			 new StandardCategoryToolTipGenerator());
			 }
			 if (urls) {
			 renderer.setBaseItemURLGenerator(
			 new StandardCategoryURLGenerator());
			 }
			 
			 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, 
			 renderer);
          //CategoryPlotExtension plot = new CategoryPlotExtension (dataset, categoryAxis, valueAxis, 
			 //renderer);
			 plot.setOrientation(orientation);
			 JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
			 plot, legend);
			 
			 return chart;
			 
			}
}
What am I missing? Hints / help appreciated.

rhobit
Posts: 9
Joined: Wed Apr 02, 2014 8:43 am
antibot: No, of course not.

Re: Problems reusing ChartFactory.createStackedBarChart(...)

Post by rhobit » Tue Apr 08, 2014 11:03 am

Solved. I had to set the background and grid lines manually.
CategoryPlot plot.setRangeGridlinesVisible(false);

Still strange that this was not necessary using the original ChartFactory...

Locked