Inserting non-numerical characters into tick labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tox0tes
Posts: 34
Joined: Tue Aug 05, 2008 7:05 pm

Inserting non-numerical characters into tick labels

Post by tox0tes » Wed Sep 03, 2008 11:45 pm

I have an XYLineChart that displays time in HHh MM' SS" .... however I cannot figure out how to have this displayed since the XYLineChart only takes numbers as tick labels.

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Thu Sep 04, 2008 12:09 am

Use a DateAxis for the domain axis. If you want to specify how the axis labels are formatted, create a custom DataFormat and assign it with setDateFormatOverride(java.text.DateFormat). The JavaDoc entries and the internet should be able to fill in the rest of the details.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

tox0tes
Posts: 34
Joined: Tue Aug 05, 2008 7:05 pm

Post by tox0tes » Thu Sep 04, 2008 1:25 am

Code: Select all

Caused by: java.lang.ClassCastException: org.jfree.chart.axis.NumberAxis
[17:18:40.423] {http--8080-2} 	at java:167)
this is line 167:

Code: Select all

DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); 
Richard, can I pay you $40 to write me sample code that simply displays a number representing milliseconds (472832837) and displays it as HHh MM' SS" on an axis? I have asked similar questions multiple times and get the same response: "look on the internet, search the forum, etc..." but there is no resource on the internet that talks about this. I have battling this problem for 2 months and I give up.

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Thu Sep 04, 2008 1:59 am

tox0tes wrote:Richard, can I pay you $40 to write me sample code that simply displays a number representing milliseconds (472832837) and displays it as HHh MM' SS" on an axis?
As much as I appreciate the offer of $40, I will have to decline. I do have a few minutes, so I gave this a quick look. Try the following:

Code: Select all

import java.text.SimpleDateFormat

DateAxis domainAxis = new DateAxis("time");
domainAxis.setDateFormatOverride(new SimpleDateFormat("HH'h' mm'' ss'"'"));

plot.setDomainAxis(domainAxis);
I believe the pattern is correct for what you desire. You may or may not have to escape the double-quote for the seconds (I suspect you do). If you want to understand what this is doing, take a look at the SimpleDateFormat class.
tox0tes wrote:I have asked similar questions multiple times and get the same response: "look on the internet, search the forum, etc..." but there is no resource on the internet that talks about this. I have battling this problem for 2 months and I give up.
You have to understand that the forum is run by volunteers and only a few members of the forum are active participants with respect to answering posts. My participation in the forum varies wildly with the amount of work I have to complete for my employer (AMD). The most I can spare is to point someone in the correct direction and hope that they have the general skills and/or knowledge to go from there. JFreeChart is a project intended for developers with a good understanding of Java (or programming in general). A certain amount of self-reliance is expected, but I admit it can be irritating at times.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Thu Sep 04, 2008 2:13 am

As an FYI, David Gilbert does offer support contracts for JFreeChart. I do not know what his fees are, but I am sure you can disuss the details with him via email. Unlike myself, he actually works for Object Refinery Limited and does consulting for a business.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

tox0tes
Posts: 34
Joined: Tue Aug 05, 2008 7:05 pm

Post by tox0tes » Thu Sep 04, 2008 7:12 pm

Thanks Richard, that code did it! That just made my day.

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Thu Sep 04, 2008 7:28 pm

tox0tes wrote:Thanks Richard, that code did it! That just made my day.
You are welcome. If you still feel like paying $40 for the answer, write a check in that amount to the charity of your choice. I think that would be a fair exchange.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

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 » Fri Sep 05, 2008 2:11 pm

RichardWest wrote:You are welcome. If you still feel like paying $40 for the answer, write a check in that amount to the charity of your choice. I think that would be a fair exchange.
Richard, thank you very much for the generosity you've displayed here. I really really appreciate the contribution you've made in the JFreeChart forum (not to mention the codebase!) over the last few years. I can hardly offer you a "fair exchange" in return, but at least I can make a gesture - so just now I donated GBP50 (about US$90) to WaterAid on your behalf:

http://www.wateraid.org/

Thanks!

Dave Gilbert
JFreeChart Project Leader

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Fri Sep 05, 2008 5:31 pm

David,
Thank you for your kind words and generous contribution.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

Locked