Alignment problem in vertical bars and category labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
arunsiva
Posts: 3
Joined: Wed Jul 11, 2012 2:15 pm
antibot: No, of course not.

Alignment problem in vertical bars and category labels

Post by arunsiva » Thu Jul 12, 2012 6:48 am

Hi,

I am using bar3d chart and the same is designed using ireport 4.5.1 and the jfreechart-1.0.14 is used
All properties are set in the jrxml and the chart renders without any errors
but the 3Dbars and the corresponding categoryTicklabels are not aligned properly (pls see the attachment), in the middle part of the chart, bars and the categoryTicklabels meet at the same point but going outer wards (both sides) there a gap is formed between the bars and the categoryTicklabels. I have been told that by using a customizer class I can fix this. if so please let me know what properties i have to set in the customizer class to fix this problem.

Thanks in advance...
Arun

Image

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: Alignment problem in vertical bars and category labels

Post by matinh » Thu Jul 12, 2012 1:23 pm

Hi!

JFreeChart has nothing such as "Customizers". This seems to come from JasperReport and has nothing to do with your concrete problem.

Your problem is, you are using the CategoryDataset in a wrong way. You use different series with a single item in each series, when you want to use a single series with multiple items in it.

If you need further assistance post the code that produces your dataset first.

hth,
- martin

arunsiva
Posts: 3
Joined: Wed Jul 11, 2012 2:15 pm
antibot: No, of course not.

Re: Alignment problem in vertical bars and category labels

Post by arunsiva » Thu Jul 12, 2012 2:09 pm

Hi,

Thank you for the reply.. actually i have implemented the chart in jasper reports
and the Customizer belongs to jasper engine. Since I am using jasper reports there are limitations in setting the properties
of the chart within the jrxml file.

Please let me know if any other options are available.

In the category data set (As seen in the attached jrxml code) i have 2 fields "states" and their corresponding "values".

any way I tried one fix which is some what working (see the below code) but the width of the bar decreased by doing this
what i have done is i have overridden the customize method of jrchartcustomizer which can handle jfree chart object.

chart.getCategoryPlot().getDomainAxis().setCategoryMargin(0.7);
renderer.setItemMargin(0.0);

Code: Select all

<categoryDataset>
		<categorySeries>
			<seriesExpression><![CDATA[$F{STATE}]]></seriesExpression>
			<categoryExpression><![CDATA[$F{STATE}]]></categoryExpression>
			<valueExpression><![CDATA[$F{LAENDER}]]></valueExpression>
			<labelExpression><![CDATA["" +$F{LAENDER}]]></labelExpression>
		</categorySeries>
</categoryDataset>
Thanks again..
Arun

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: Alignment problem in vertical bars and category labels

Post by matinh » Thu Jul 12, 2012 2:25 pm

Hi again!

I know JasperReports but I've got close to no experience when it comes to using charts in it. Anyway, it's none of the visual properties of the chart that make it look like it does. It's your data that isn't used as supposed.

Could you eventually try to change to code you just posted and see if it helps.
Please replace

Code: Select all

<seriesExpression><![CDATA[$F{STATE}]]></seriesExpression>
with

Code: Select all

<seriesExpression><![CDATA["dummySeries"]]></seriesExpression>
hth,
- martin

arunsiva
Posts: 3
Joined: Wed Jul 11, 2012 2:15 pm
antibot: No, of course not.

Re: Alignment problem in vertical bars and category labels

Post by arunsiva » Fri Jul 13, 2012 11:13 am

Hi

thanks a lot that worked indeed..... but now my chart legend is replaced by "dummyValues"
my requirement is that the series and series name should be same.

Please suggest me how this can be achieved in category series..

Regards,
Arun

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Re: Alignment problem in vertical bars and category labels

Post by matinh » Fri Jul 13, 2012 11:39 am

A CategorySet is able to represent data in two-dimensions (like a table with rows and columns):

Code: Select all

 +-+-+-+
 |a|b|c|
 +-+-+-+
 |d|e|f|
 +-+-+-+
 |g|h|i|
 +-+-+-+
Your data just has a single row (or column):

Code: Select all

 +-+-+-+
 |a|b|c|
 +-+-+-+
 | | | |
 +-+-+-+
 | | | |
 +-+-+-+
But you are setting row and column keys in a way, that you use it like this:

Code: Select all

 +-+-+-+
 |a| | |
 +-+-+-+
 | |b| |
 +-+-+-+
 | | |c|
 +-+-+-+
In your original chart you thus have redundant information: the country-code is output in the legend and below each bar. In the legend it comes from the key of the series (row). Blow the bar it comes from the key of the category (column). You can't have it all. Either choose the series resp. category keys (row resp. column keys) to be equal on all datapoints, or live with a chart as you posted.

If you want the legend match your expectations but don't care about the category-keys just replace the <categoryExpression> instead of the <seriesExpression> and eventually hide the labels via the axis-API.

hth,
- martin

Locked