FIXED: BarChart - Bars only have 1px width

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Manakin
Posts: 4
Joined: Thu Feb 05, 2009 1:46 pm

FIXED: BarChart - Bars only have 1px width

Post by Manakin » Thu Feb 05, 2009 2:18 pm

hi everyone,

i'm taking my first steps in JFreeChart and got a working Chart in my app

everything looks fine but my bars have a thickness of 1px

here my source:

Code: Select all

CategoryAxis yAxis = new CategoryAxis();
    	yAxis.setMaximumCategoryLabelLines(1);
    	yAxis.setCategoryMargin(0.01);
    	yAxis.setLowerMargin(0.08);
    	ValueAxis xAxis = new NumberAxis();
    	xAxis.setLowerMargin(0.08);
    	xAxis.setUpperMargin(0.08);
    	BarRenderer renderer = new BarRenderer();
    	renderer.setBase(0);
    	renderer.setMinimumBarLength(0);
    	renderer.setMaximumBarWidth(1.0);
    	renderer.setItemMargin(0.0);
    	renderer.setShadowVisible(false);
    	renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.BOTTOM_CENTER));
    	renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.TOP_CENTER));
    	StandardCategoryItemLabelGenerator stditemlbl = 
			new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getNumberInstance());
    	renderer.setBaseItemLabelsVisible(true);
    	renderer.setBaseItemLabelGenerator(stditemlbl);
    	
    	for (int i = 0; i < data.getValuePairs().size(); i++) {
    		renderer.setSeriesOutlineStroke(i, new BasicStroke(50));
    		renderer.setSeriesStroke(i, new BasicStroke(50));
    		renderer.setSeriesFillPaint(i, Color.BLUE);
    		renderer.setSeriesPaint(i, Color.BLUE);    		
    	}
    	CategoryPlot plot = new CategoryPlot(dataset, yAxis, xAxis, renderer);
    	plot.setBackgroundPaint(Color.WHITE);
    	plot.setRangeGridlinePaint(Color.BLUE);
    	plot.setDomainGridlinePaint(Color.BLUE);
    	plot.setRangeGridlineStroke(GRIDLINE_STROKE);
    	plot.setDomainGridlineStroke(GRIDLINE_STROKE);
    	plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    	plot.setOrientation(PlotOrientation.HORIZONTAL);
    	
    	JFreeChart chart = new JFreeChart(null, null, plot, false);
    	chart.setBackgroundPaint(Color.WHITE);
 
dunno if its the right way to build a barchart

any help is welcome
Last edited by Manakin on Mon Feb 09, 2009 1:16 pm, edited 1 time in total.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Feb 05, 2009 2:57 pm

The bar widths are automatically calculated and will depend on the chart or plot width and the number of items in your dataset.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Manakin
Posts: 4
Joined: Thu Feb 05, 2009 1:46 pm

Post by Manakin » Thu Feb 05, 2009 4:14 pm

hmm i have a height of 200 and 8 entries in my dataset

in basic: what i want to provide is 8 bars with a space of 1-2px and a height of at least with 10-15px

should i use another chart for this purpose or is the barchart the right descission

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Feb 05, 2009 5:56 pm

Can you log the results from dataset.getRowCount() and dataset.getColumnCount() and just confirm that you only have 8 items in your dataset? The number of items is those two results multiplied together.

Or post a small self-contained demo that reproduces the bug?
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

skalluraya
Posts: 15
Joined: Fri Jan 23, 2009 5:36 am

Post by skalluraya » Sat Feb 07, 2009 2:03 pm

I have a same problem. can we set the with of bars. I do not want change the size of image for less number of bar.

Is it possible

Manakin
Posts: 4
Joined: Thu Feb 05, 2009 1:46 pm

Post by Manakin » Mon Feb 09, 2009 9:26 am

sry for my late reply, i was already on weekend :)

results:
dataset.getRowCount() = 9
dataset.getColumnCount() = 9

another strange thing: it doesnt matter what size the image has

i tried it with "height 800" but my bars didnt resize :(

Manakin
Posts: 4
Joined: Thu Feb 05, 2009 1:46 pm

Post by Manakin » Mon Feb 09, 2009 1:15 pm

fixed it

the problem was in the dataset (ur right david thx!)

i had 9 different rows and 9 different columns -> switched them to 9 columns with 1 unique row name key

works fine now
thx!

ele_28
Posts: 1
Joined: Wed May 23, 2012 11:44 pm
antibot: No, of course not.

Re: FIXED: BarChart - Bars only have 1px width

Post by ele_28 » Wed May 23, 2012 11:47 pm

Yup, had the same issue. 9 different row names. Thanks for the post David!

Locked