Localize Date labels on a Bar chart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
glindholm
Posts: 3
Joined: Fri Jun 22, 2007 3:05 pm

Localize Date labels on a Bar chart

Post by glindholm » Fri Jun 22, 2007 3:52 pm

I'm using JFreeChart as part of JasperReports.

I've defined an xyBarChart with a timeSeriesDataset and setting the Locale.

All the dates on the report are being properly localized except for the date labels on the Bar Chart which alway are in English.

Is this a known issue with JFreeChart?
Or is this an issue with JasperReports?


Versions:
jfreechart-1.0.6.jar
jcommon-1.0.10.jar
jasperreports-1.3.4.jar
java 5
Windows XP Pro
Default locale en_US

Keywords: I18N Internationalization

skunk
Posts: 1087
Joined: Thu Jun 02, 2005 10:14 pm
Location: Brisbane, Australia

Post by skunk » Fri Jun 22, 2007 7:44 pm

Did you try setting your locale? Internally, the date is formatted using an instance of java.text.SimpleDateFormat and the formatting should automagically match the default locale.

glindholm
Posts: 3
Joined: Fri Jun 22, 2007 3:05 pm

Post by glindholm » Fri Jun 22, 2007 9:30 pm

I've spent all day in the debugger and I now understand what is going wrong.

JasperReports is calling org.jfree.chart.ChartFactory.createXYBarChart(...) to created the JFreeChart.

ChartFactory.createXYBarChart(...) does not accept a Locale and TimeZone to use.

ChartFactory.createXYBarChart(...) does a
domainAxis = new DateAxis(xAxisLabel); which does a
DateAxis.createStandardDateTickUnits(TimeZone zone)
this uses SimpleDateFormat() to create the DateFormat objects.

DateFormat f6 = new SimpleDateFormat("MMM-yyyy");

SimpleDateFormat() uses the default Locale when a Locale is not supplied.
Also it's using the default TimeZone since again createXYBarChart() does not allow you specify the TimeZone.

I'm using this in a web application, I need it to use the user's Locale and TimeZone not the server's.

I would suggest the following changes:
- add methods to ChartFactory that accept a Locale and TimeZone
- Any place where SimpleDateFormat() is use, use the alternate constructor that also take the locale.
- pass the locale and timezone through to everything that creates a DateFormat.


I would be more then willing to help out with the development and creating a patch if a committer will work with me to get the changes back into the project.

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 » Mon Jun 25, 2007 4:39 pm

This thread is now continuing on the JFreeChart developers mailing list.
David Gilbert
JFreeChart Project Leader

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

daniel79
Posts: 1
Joined: Mon Aug 20, 2007 4:17 pm

i18n date axis

Post by daniel79 » Mon Aug 20, 2007 4:21 pm

There should be also option for setting the locale for date axis.
Auto tick unit is very useful but for now can't be used with i18n.
Is this possible?

Locked