We get minimum and maximum times from an external source when asked to display a flex graph, and so we use a DateTimeAxis to display the time (x) axis. Because of this, we can't hard-code labelUnits
and interval
, but the default implementation leaves something to be desired. Does anybody know of libraries that help DateTimeAxis autoconfigure labelUnits
and interval
more usefully?
In the following example, it puts in the first label at 01:04 and the next at 01:18. What the? 01:15 and the next at 01:30 would be user-friendly. Putting in an interval="15"
, and we get 01:04 and 01:19 - not really much better.
Here is a complete example. (Omitting labelUnits
with these minimum
and maximum
results in no labels at all, so I put it in):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">
<mx:DateFormatter id="df" formatString="JJ:NN:SS" />
<mx:Script>
<![CDATA[
private const minimum:Date = new Date( "Apr 1 2011 01:03:54 AM");
private const maximum:Date = new Date( "Apr 1 2011 03:07:54 AM");
private function labelFunction(item:Object,
field:String,
index:Number):String {
return df.format(item as Date);
}
]]>
</mx:Script>
<mx:CartesianChart width="600" height="200">
开发者_开发知识库 <mx:horizontalAxis>
<mx:DateTimeAxis
minimum = "{minimum}"
maximum = "{maximum}"
displayLocalTime="true"
labelFunction="labelFunction"
labelUnits="minutes"
/>
<!--
interval="15"
-->
</mx:horizontalAxis>
</mx:CartesianChart>
</mx:Application>
Gives this
I'd rather not have to re-invent the wheel and calculate labelUnits
and interval
based on:
- minimum and maximum time
- the width of the graph
- the font size
- anything else?
So I'm hoping I missed something or for an AutoDateTimeAxis or some such implementation.. ;-) Do you know of any?
I had a similar problem with the DateTimeAxis and ended up using a category axis instead, using a custom label function to format the date labels.
There is a similar bug to do with daylight savings time which will rear its head if your range spans both DST and non DST, the interval will never match due to the extra/missing hours in the overlap.
精彩评论