ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Locale-sensitive DateAxis in Java
Posted by Walt on Jul-06-2011 02:38
Hi, My name is Walt. I am looking for some hints relating to ChartDirector?s Date Axis
formatting. The project we?re working on is using the Java version of ChartDirector.

The charts being rendered in our project are done so in a fully internationalized
environment. Thus far, it has proven tricky to work around formatting dates using multiple
timezones in a threadsafe manner ? however we have implemented a workaround exploiting
our understanding that ChartDirector uses TimeZone.getDefault() to format timestamps by
writing layer on top of TimeZone.setDefault() so that we are always setting a "threadlocal"
timezone. This is an elegant workaround to the multiple timezone issue.

However, we still don?t understand how Chart Director establishes a Locale to use when
formatting dates. We wish to understand this better so that we can proceed in the most
effective manner possible ? ideally using an alternative approach to using
BaseChart.setMonthNames(), etc..

Does ChartDirector behave similarly with formatting dates to a Locale? Locale.setDefault
seems to have no impact on the output.

If the issue isn't clear, please let me know.
Thank you for your time.

  Re: Locale-sensitive DateAxis in Java
Posted by Peter Kwan on Jul-06-2011 21:13
Hi Walt,

ChartDirector does not use any Locale settings to format dates. It just uses the settings in setMonthNames, setWeekDayNames, etc..

Actually, ChartDirector internally does not use TimeZone.getDefault() as well. ChartDirector internally uses "second elapsed since 01-01-0001 00:00:00" and is timezone independent. Given the (y, m, d, h, n, s), the "second elapsed since 01-01-0001 00:00:00" can be computed using Chart.chartTime.

However, in Java, it is common to use java.util.Date to represent date/time. If you pass java.util.Date objects to ChartDirector, ChartDirector will need to change them to the timezone independent format (nominal second elapsed since 01-01-0001 00:00:00). This requires getting the (y, m, d, h, n, s) components. ChartDirector will just get them directly using standard Java API without configuring the TimeZone. By default, if the TimeZone is not configured, the Java VM will use the default time zone.

Hope this can help.

Regards
Peter Kwan

  Re: Locale-sensitive DateAxis in Java
Posted by Walt on Jul-08-2011 00:44
Attachments:
Thanks for the quick response, Peter.

My main point of concern was the use or non-use of Locale.getDefault() as it affects the
work we're doing in internationalizing our image output.

For quite a while, I had convinced myself that the Java ChartDir API specific to label
formatting was just a layer on top of java.util.Format (which is both TimeZone and Locale-
aware) - and that CD's use of TimeZone.getDefault() was the result of not exposing a
timezone parameter in the API. But through this thread, lurking other threads and reading
the API more carefuly, I've realized that's not the case and that the formatting is truly
custom. With this, I've been able to proceed with relative success.

__

In what seems like the last (small) issue I'm having, I think I'm going to need a tip.
For all instances of charts (BaseChart.class), I'm using the BaseChart.setNumberFormat
method to localize these formatting characters. I'm using the overloaded, 3 parameter
method and specifying all 3 characters. By default (english, or if not specified), I'd
like to just use the default "noop" char '~' as for the "thousand separator" defined in the
API. However, this doesn't seem to be working as specified, as axis labels take the literal
value and insert it into the formatted label. (see attached screenshot)

Are you or is anyone else aware of any bugs that might cause this or any common mistakes
in utilizing this feature?

Thanks again for your help.
-Walt
ss.jpg

  Re: Locale-sensitive DateAxis in Java
Posted by Peter Kwan on Jul-08-2011 01:38
Hi Walt,

The '~' formatting character is in fact broken in ChartDirector for JSP/Java. Instead, please use the null character '\\0'.

We will fix the above problem in the next version of ChartDirector, which would support both the '~' and the '\\0' characters.

Hope this can help.

Regards
Peter Kwan

  Re: Locale-sensitive DateAxis in Java
Posted by Walt on Jul-08-2011 04:30
This does help. Thank you.

The only problem I'm having now deals with Japanese unicode characters displaying as
empty boxes. I feel like I understand what the problem is based on separate support
threads - that it's most likely a Font issue and could get particularly hairy considering that
this application will be OS-agnostic on the server-side.

Thanks for everything.

  Re: Locale-sensitive DateAxis in Java
Posted by Peter Kwan on Jul-09-2011 01:00
Hi Walt,

You are correct. If you character is a displayed as a square, it means Java (and therefore ChartDirector) understands your text. However, it is unable to render the character because the font you are using do not have the character.

Even if a Java application is "OS-agnostic", it still requires the Java VM is configured correctly only the OS. For example, the OS needs to have the correct version and type of Java VM. If it is "headless", it needs to start Java in headless mode (and using a Java version that supports headless mode). It also needs to have the proper fonts required by the application.

For the fonts, the application can include its own fonts. (ChartDirector supports the use of private font files.) In this way, it can work even if the Java installation does not have the necessarily fonts.

Hope this can help.

Regards
Peter Kwan

  Re: Locale-sensitive DateAxis in Java
Posted by Walt on Jul-14-2011 06:31
Yes. This was fairly straightforward to prove out. Thanks for everything.