Thousands, millions, billions, & gazillions?
-
- Posts: 106
- Joined: Fri May 27, 2005 7:44 pm
- Location: Boulder, CO
- Contact:
Thousands, millions, billions, & gazillions?
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?
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?
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: Thousands, millions, billions, & gazillions?
There isn't. Gazillion is yet-another-made-up number. See this Wikipedia entry for some interesting history and examples.DavidThi808 wrote:ps - what order of magnitude is a gazillion?
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 106
- Joined: Fri May 27, 2005 7:44 pm
- Location: Boulder, CO
- Contact:
Re: Thousands, millions, billions, & gazillions?
Sorry, I guess I should have put a after the ps - that part was a joke.DavidThi808 wrote:ps - what order of magnitude is a gazillion?
Seriously - can the axis be set to divide all values for thou/mil/bil?
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: Thousands, millions, billions, & gazillions?
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:Sorry, I guess I should have put a after the ps - that part was a joke.
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.DavidThi808 wrote:Seriously - can the axis be set to divide all values for thou/mil/bil?
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 106
- Joined: Fri May 27, 2005 7:44 pm
- Location: Boulder, CO
- Contact:
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
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.DavidThi808 wrote:I overrode NumberFormat and it works great - piece of cake.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
-
- Posts: 106
- Joined: Fri May 27, 2005 7:44 pm
- Location: Boulder, CO
- Contact:
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);
}
}
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
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
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
-
- Posts: 106
- Joined: Fri May 27, 2005 7:44 pm
- Location: Boulder, CO
- Contact:
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
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.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.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA