Inverting an Axis on a chart
I had a case on my latest project where I had a chart that needed to not start at 0,0 as most do. Rather this chart, and the data it represented needed to have it’s Y Axis inverted. The better numbers were closer to the bottom, and higher in value. 0 was bad.
I did some searching and there seemed to be one common approach. manually invert your data. I wasn’t sure that was what I wanted, but it turned out that that approach worked really well.
in the function that creates the data for the chart, I simply invert the values by subtracting 2* the value, from itself
val.perfRank = (performance – (performance * 2));
val.availRank = (availability – (availability * 2));
val.consistRank = (consistency – (consistency * 2));
After populating my dataprovider with the inverted values, all I needed was a label function to undo my voodoo.
private function rankLabelFunction(labelValue:Object, previousLabelValue:Object, axis:IAxis):Number
{
var newAxisValue:Number = Number(labelValue);
newAxisValue = (newAxisValue + (Math.abs(newAxisValue) * 2));
return newAxisValue;
}
You’ll want to make sure to do the absolute value, LOL. Otherwise you’ll be like me, “Why is the negative number, even bigger? Oh yeah! Duh!” Math, not my strong suit.
There may be more elegantĀ ways, I sorta hope there are or will be, but this is a pretty straight forward way to simply put your lowest value at the top of your axis, which is what I needed.
Lijit Search
Lijit SearchTags
Categories
interestinglinks
Blogroll
Recent Comments
Archives
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- March 2005
