I have an app which displays any type of chart based on actionscript class
definitions. It can't be done in mxml because the charts get drawn at runtime.
It has worked fine until recently. The daylight savings time change has made
it go all out of whack. I rebuilt a sample version in mxml however and it
displays correctly. I've attempted to mimic this in a hard coded actionscript
version as well but it just doesn't work.
In the code below, the columnWidthRatio is set to 1.1 so that the columns
slightly overlap, but in the actionscript version, the bars are tiny with wide
gaps between them. Also, if I set the labelUnits to 'hours', the chart won't
work at all. It won't even draw anything, but just times out.
I am using Flex 3.3 on a Mac. I've also tried Flex 3.5a but it didn't work
with that either.
[Bindable]
public var DECKER:Array = [
{point1:"Tue Mar 16 00:00:00 GMT-0400 2010",
point2:6.021350380920805},
{point1:"Mon Mar 15 00:00:00 GMT-0400 2010",
point2:12.432308140005917},
{point1:"Sun Mar 14 00:00:00 GMT-0500 2010",
point2:19.558957234168425}
];
// actionscript version which doesn't work
public function makeDateChart(genericChart:CartesianChart,
genericLegend:Legend, chartPanel:ChartPanel,
chart:ChartObject):void {
// ChartObject is a custom object which holds display
information
// as well as al the SeriesObjects (see below)
var axisList:ArrayCollection = chart.getAxisList();
var seriesArray:Array = new Array();
var hAxis:DateTimeAxis = new DateTimeAxis();
for (var i:int=0; i<axisList.length; i++) {
var axis:AxisObject = axisList.getItemAt(i)
as AxisObject;
if (axis.getID() == "x Axis") {
hAxis.labelUnits = "days";
genericChart.horizontalAxis = hAxis;
}
else {
// Define vertical axis
var vAxis:LinearAxis = new LinearAxis();
genericChart.verticalAxis = vAxis;
for (var j:int=0;
j<axis.getSeriesList().length; j++) {
// custom data object which
holds data and display settings
var ser:SeriesObject =
axis.getSeriesList().getItemAt(j) as SeriesObject;
var columnSeries:ColumnSeries =
new ColumnSeries();
// bind data...It doesn't
matter if I bind 'pointList' or DECKER to this
// either way it doesn't work
for columnSeries- it does work for the
// mxml object testCol (see
prev post for static version of chart)
BindingUtils.bindProperty(columnSeries, "dataProvider", this, "DECKER");
BindingUtils.bindProperty(colSer, "dataProvider", this, "DECKER");
// pointList would be used for
the dynamic version
//
BindingUtils.bindProperty(columnSeries, "dataProvider", ser, "pointList");
//
BindingUtils.bindProperty(colSer, "dataProvider", ser, "pointList");
columnSeries.columnWidthRatio =
1.1;
// columnSeries.displayName =
ser.name;
columnSeries.xField="point1";
columnSeries.yField="point2";
seriesArray.push(columnSeries);
}
}
}
genericChart.series =
seriesArray;//.toArray().reverse();
genericChart.percentWidth = 100;
genericChart.showDataTips = true;
var hb:HBox = new HBox();
hb.addChild(genericChart);
this.addChild(hb);
}
<!-- mxml version which works -->
<mx:HBox backgroundColor="white">
<mx:CartesianChart showDataTips="true" id="testCol" >
<mx:horizontalAxis>
<mx:DateTimeAxis labelFunction="fullTimeLabelFunction"
dataUnits="days"/>
</mx:horizontalAxis>
<mx:verticalAxis>
<mx:LinearAxis />
</mx:verticalAxis>
<mx:series>
<mx:ColumnSeries id="colSer" columnWidthRatio="1.1"
yField="point2" xField="point1" displayName="points"/>
</mx:series>
</mx:CartesianChart>
</mx:HBox>