Add a DateChooser control
<!--
Code from Flex 4 Documentation "Using Adobe Flex 4".
This user guide is licensed for use under the terms of the Creative Commons Attribution
Non-Commercial 3.0 License.
This License allows users to copy, distribute, and transmit the user guide for noncommercial
purposes only so long as
(1) proper attribution to Adobe is given as the owner of the user guide; and
(2) any reuse or distribution of the user guide contains a notice that use of the user guide is governed by these terms.
The best way to provide notice is to include the following link.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
-->
<!-- charts/DisabledDateRangesWithDateChooser.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%"
height="100%" creationComplete="init()">
<mx:Script>
import mx.collections.ArrayCollection;
[Bindable]
public var aapl:ArrayCollection = new ArrayCollection([
{date:"08/01/2007", close:42},
{date:"08/02/2007", close:43},
{date:"08/03/2007", close:43},
{date:"08/06/2007", close:42},
{date:"08/07/2007", close:38},
{date:"08/08/2007", close:37},
{date:"08/09/2007", close:39},
{date:"08/10/2007", close:41},
{date:"08/13/2007", close:45},
{date:"08/14/2007", close:47},
{date:"08/15/2007", close:48},
{date:"08/16/2007", close:42},
{date:"08/17/2007", close:43},
{date:"08/20/2007", close:45},
{date:"08/21/2007", close:50},
{date:"08/22/2007", close:51},
{date:"08/23/2007", close:55},
{date:"08/24/2007", close:51},
{date:"08/27/2007", close:49},
{date:"08/28/2007", close:51},
{date:"08/29/2007", close:50},
{date:"08/30/2007", close:49},
{date:"08/31/2007", close:54}
]);
// Define weekend days to be removed from chart.
[Bindable]
private var offDays:Array = [0,6];
[Bindable]
private var dateChooserDisabledRanges:Array = [];
private function init():void {
// Limit selectable range to August of 2007 on DateChooser.
dateChooserDisabledRanges = [
{rangeEnd: new Date(2007, 6, 31)},
{rangeStart: new Date(2007, 8, 1)}
];
// Disable weekend days on DateChooser.
dc1.disabledDays = [0, 6];
}
[Bindable]
private var offRanges:Array = new Array([]);
private function onDateChange(e:Event):void {
// Get the start and end date of the range.
var startDate:Date = e.currentTarget.selectedRanges[0].rangeStart;
var endDate:Date = e.currentTarget.selectedRanges[0].rangeEnd;
var d:Object = {rangeStart:startDate, rangeEnd:endDate};
// Add object to list of ranges to disable on chart.
offRanges.push(d);
// Refresh the chart series with the new offRanges.
var mySeries:Array = [];
mySeries.push(series1);
mychart.series = mySeries;
// Show the current ranges.
ta1.text = "";
for (var i:int = 0; i < offRanges.length; i++) {
for (var s:String in offRanges[i]) {
ta1.text += s + ":" + offRanges[i][s] + "\n";
}
}
}
private function clearAllDisabledDates():void {
offRanges = [];
dc1.selectedDate = null;
ta1.text = "";
}
</mx:Script>
<mx:Panel title="DateTimeAxis" width="100%" height="100%">
<mx:HBox>
<mx:LineChart id="mychart" dataProvider="{aapl}"
showDataTips="true">
<mx:horizontalAxis>
<mx:DateTimeAxis id="dtAxis" dataUnits="days"
disabledDays="{offDays}" disabledRanges="{offRanges}" />
</mx:horizontalAxis>
<mx:verticalAxis>
<mx:LinearAxis minimum="30" maximum="60" />
</mx:verticalAxis>
<mx:series>
<mx:LineSeries id="series1" yField="close" xField="date"
displayName="AAPL" />
</mx:series>
</mx:LineChart>
<mx:DateChooser id="dc1" showToday="false"
click="onDateChange(event)" displayedMonth="7"
displayedYear="2007"
disabledRanges="{dateChooserDisabledRanges}" />
</mx:HBox>
<mx:Button id="b1" label="Refresh" click="clearAllDisabledDates()" />
<mx:TextArea id="ta1" width="600" height="400" />
</mx:Panel>
</mx:Application>
Related examples in the same category