I'm looking to center the labels on a horizontal DateTimeAxis.  Given the
two charts below, I want the first chart to look like the second one.  The
second one uses a CategoryAxis, but this doesn't work very well because in
my real project I have a lot of data and just need to change the
minimum/maximum properties on the DateTimeAxis in order to scroll around in
the data.  In this example, I am using normal rotation.  But in my real one,
I'm using a style that sets the labelRotation to 90.  I left it out of the
example for simplification, but just thought I'd mention it in case it might
come into play.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>
  <mx:Script>
    <![CDATA[
      import mx.formatters.DateFormatter;
      import mx.collections.ArrayCollection;
      [Bindable] public var d1:ArrayCollection = new ArrayCollection([
        {timestamp:new Date("1/1/2007"), data:9},
        {timestamp:new Date("2/1/2007"), data:16},
        {timestamp:new Date("3/1/2007"), data:17},
        {timestamp:new Date("4/1/2007"), data:35},
        {timestamp:new Date("5/1/2007"), data:11},
        {timestamp:new Date("6/1/2007"), data:20},
        {timestamp:new Date("7/1/2007"), data:9},
        {timestamp:new Date("8/1/2007"), data:21},
        {timestamp:new Date("9/1/2007"), data:14},
        {timestamp:new Date("10/1/2007"), data:22},
        {timestamp:new Date("11/1/2007"), data:16},
        {timestamp:new Date("12/1/2007"), data:19}
      ]);

      private var df:DateFormatter = new DateFormatter;

      private function getCatLabel(categoryValue:Object,
previousCategoryValue:Object,
          axis:CategoryAxis, categoryItem:Object):String
      {
        df.formatString = "MM/YY";
        return df.format(categoryValue);
      }
    ]]>
  </mx:Script>

  <mx:CartesianChart id="chart1" width="100%" height="100%"
dataProvider="{d1}">

    <mx:horizontalAxis>
      <mx:DateTimeAxis id="dt" dataUnits="months" alignLabelsToUnits="false"

          minimum="{new Date('1/1/2007')}" maximum="{new
Date('1/1/2008')}"/>
    </mx:horizontalAxis>

    <mx:series>
      <mx:ColumnSeries xField="timestamp" yField="data" offset="0.5"/>
    </mx:series>
  </mx:CartesianChart>

  <mx:CartesianChart id="chart2" width="100%" height="100%"
dataProvider="{d1}">

    <mx:horizontalAxis>
      <mx:CategoryAxis categoryField="timestamp"
labelFunction="getCatLabel"/>
    </mx:horizontalAxis>

    <mx:series>
      <mx:ColumnSeries xField="timestamp" yField="data"/>
    </mx:series>
  </mx:CartesianChart>
</mx:Application>


-- 
Jason

Reply via email to