Thousands, millions, billions, & gazillions?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
DavidThi808
Posts: 106
Joined: Fri May 27, 2005 7:44 pm
Location: Boulder, CO
Contact:

Thousands, millions, billions, & gazillions?

Post by DavidThi808 » Fri Jul 27, 2007 3:08 am

Hi;

Is there a way to tell an axis to divide all numbers by 1,000; 1,000,000; and 1,000,000,000 so if all my values are 1,000 - 29,000 the axis is 1 - 29?

thanks - dave

ps - what order of magnitude is a gazillion?

jwenting
Posts: 157
Joined: Sat Jul 15, 2006 7:46 am

Post by jwenting » Fri Jul 27, 2007 6:17 am

there's no such number as a "gazillion". It's just a figure of speech, rather like "1, 2, many" and indicates any number large enough to be incomprehensible.

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

Re: Thousands, millions, billions, & gazillions?

Post by RichardWest » Fri Jul 27, 2007 6:19 am

DavidThi808 wrote:ps - what order of magnitude is a gazillion?
There isn't. Gazillion is yet-another-made-up number. See this Wikipedia entry for some interesting history and examples.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

DavidThi808
Posts: 106
Joined: Fri May 27, 2005 7:44 pm
Location: Boulder, CO
Contact:

Re: Thousands, millions, billions, & gazillions?

Post by DavidThi808 » Fri Jul 27, 2007 3:23 pm

DavidThi808 wrote:ps - what order of magnitude is a gazillion?
Sorry, I guess I should have put a :D after the ps - that part was a joke.

Seriously - can the axis be set to divide all values for thou/mil/bil?

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

Re: Thousands, millions, billions, & gazillions?

Post by RichardWest » Fri Jul 27, 2007 10:36 pm

DavidThi808 wrote:Sorry, I guess I should have put a :D after the ps - that part was a joke.
I knew it was a joke. It just sparked my curiousity as to the origin of fictious numbers. That is why I supplied the link.
DavidThi808 wrote:Seriously - can the axis be set to divide all values for thou/mil/bil?
Now that I have thought about this, I believe the easiest way to do this would be to keep the data intact and change the tick labels. You want to keep the data as 1,500,000 instead of 1.5 (for instance) in case you wish to use the data in another location. You can change the tick labels in several ways: create a custom TickUnitSource, override the axis' refreshTicks(), or create a NumberFormat that divides the source by the desired order of magnitude.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

DavidThi808
Posts: 106
Joined: Fri May 27, 2005 7:44 pm
Location: Boulder, CO
Contact:

Post by DavidThi808 » Mon Jul 30, 2007 11:54 pm

I overrode NumberFormat and it works great - piece of cake.

thanks - dave

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 » Tue Jul 31, 2007 10:39 am

DavidThi808 wrote:I overrode NumberFormat and it works great - piece of cake.
That's the approach I would have suggested if I'd got to this thread sooner. I'm interested in adding a few more number formatting options to JFreeChart, so if your code is fit for general purpose use and you feel like contributing it, let me know.
David Gilbert
JFreeChart Project Leader

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

DavidThi808
Posts: 106
Joined: Fri May 27, 2005 7:44 pm
Location: Boulder, CO
Contact:

Post by DavidThi808 » Tue Jul 31, 2007 3:23 pm

Here you go - it is a large and very complex class:

Code: Select all

public class DivNumberFormat extends DecimalFormat {

	private int magnitude;

	public DivNumberFormat(int magnitude) {
		this.magnitude = magnitude;
	}

	public StringBuffer format(double number, StringBuffer result, FieldPosition fieldPosition) {
		return super.format(number / magnitude, result, fieldPosition);
	}

	public StringBuffer format(long number, StringBuffer result, FieldPosition fieldPosition) {
		return super.format(number / magnitude, result, fieldPosition);
	}
}

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

Post by RichardWest » Tue Jul 31, 2007 5:26 pm

Now, if only we had a means to link the magnitude into the label of the axis using this formatter. For example, have the axis label be "counts (in thousands)" or "counts (in 1000s)" when the magnitude is 1000. Now that would be rather nifty. I think extending the NumberAxis class, automatically assigning a DivNumberFormat object, and providing a getter that returns the magnitude should do the trick. This would also allow you to change the scaling on the fly. As long as an AxisChangeEvent is fired, the chart will redraw with the updates.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

DavidThi808
Posts: 106
Joined: Fri May 27, 2005 7:44 pm
Location: Boulder, CO
Contact:

Post by DavidThi808 » Tue Jul 31, 2007 5:33 pm

Hi;

You guys know much better than me what is needed as you read this daily. But the 2 main things I think you need for the number is a multiplier (which normally would be values like 0.001, 0.000001, ...) and a pattern for the formatter.

thanks - dave

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

Post by RichardWest » Tue Jul 31, 2007 6:15 pm

david.gilbert wrote:I'm interested in adding a few more number formatting options to JFreeChart, so if your code is fit for general purpose use and you feel like contributing it, let me know.
My only suggestion before adding it would be to change the name to ScaledDecimalFormat or ScaledNumberFormat. IMHO, this seems like a slightly more descriptive name. I will also start work on the axis as well.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

Locked