Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-22-2008, 03:48 PM   #1
canuzzi
Registered User
 
Join Date: Nov 2007
Posts: 3
Default DataToLocal and DateTimeAxis

Hello group,

Ich have an areachart where I want to add an chartelement as annotation element. My Chart has a horizontal datetime axis and I want to use the datetolocal method in my chart element to place a line at a specified date to my chart. first of all I saw that I get NAN values, if I use the date-Object as attribute with datatolocal. So I experimented a little bit - and found out, that the Unix time (seconds since 1970) is in the correct scale - but around eight years to high. So a little bit of my code - first the chart, second my chart element:
Code:
<!-- some stuff -->
<mx:AreaChart id="myChart"
  dataProvider="{timeseries}">
  <mx:horizontalAxis>
      <mx:DateTimeAxis
	  dataUnits="months" interval="5"
	  labelUnits="years"
	  minimum="{start}"
	  maximum="{end}"
	  displayName="Year" />
  </mx:horizontalAxis>
  <mx:verticalAxis>
	<mx:LinearAxis displayName="EUR" />
  </mx:verticalAxis>
  <mx:series>
    	<mx:AreaSeries
              yField="value" xField="date"
              displayName="Values"/>
  </mx:series>
   <mx:annotationElements>
	<myClasses:Deadlines date="{today}"/>
   </mx:annotationElements>
</mx:AreaChart>
now the chart element
Code:
package myClasses
{
	import mx.charts.chartClasses.ChartElement;
	import flash.display.Graphics;
	import flash.geom.Point;

	[Bindable]
	public class Deadlines extends ChartElement
	{	
		private var _date:Date;

		public function Deadlines()
		{
			super();
			
		}
		
		override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
			var g:Graphics = graphics;
			g.clear();
			
			var x:Number = this.chart.dataToLocal(_date.time,0).x;
				
			g.lineStyle(2,0xFF00FF,1.0);
			g.moveTo(x,0);
			g.lineTo(x,unscaledHeight);
		}
		
		public function set date(x:Date):void { _date=x; }
		public function get date():Date { return _date; }
		
	}
}
Can anybody help me please?
canuzzi is offline   Reply With Quote
Old 02-29-2008, 02:51 PM   #2
canuzzi
Registered User
 
Join Date: Nov 2007
Posts: 3
Default

So I solved the problem, by writing the data transformation by myself. So if anybody is interested ...
Code:
package client
{
	import mx.charts.chartClasses.ChartElement;
	import flash.display.Graphics;
	import flash.geom.Point;
	import mx.controls.Alert;
	import mx.controls.Label;
	import mx.charts.AreaChart;
	import mx.charts.DateTimeAxis;
	import mx.charts.AxisRenderer;

	[Bindable]
	public class Deadlines extends ChartElement
	{	
		private var _date:Date;
		private var _label:Label;
		private var _labelText:String;
		private var _yLabel:Number;
		private var _position:String;
		private var _color:Number;
		
		public function Deadlines()
		{
			super();
			_label = new Label();
			this.addChild(_label);
			// setStyle("color",0);
			
		}
		
		override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
			var g:Graphics = graphics;
			var defaultColor:Number = 0;
			var ac:AreaChart = AreaChart(this.chart);
			var taxis:DateTimeAxis = DateTimeAxis(ac.horizontalAxis);
			g.clear();
			
			var x0:Number = (_date.time-taxis.baseline)/(taxis.maximum.time-taxis.baseline)*AxisRenderer(ac.horizontalAxisRenderer).length;
			
			//Alert.show(String(new Date(this.chart.localToData(new Point(0,0))[0])));	
			g.lineStyle(1,(_color?_color:defaultColor),1.0);
			g.moveTo(x0,0+1.5*_yLabel);
			g.lineTo(x0,unscaledHeight);
			g.moveTo(0,0);
			
			var pos:Number = 1;
			_label.setStyle("color",(_color?_color:defaultColor));
			_label.text=_labelText;
			_label.setActualSize(_label.getExplicitOrMeasuredWidth(),_label.getExplicitOrMeasuredHeight());
			if (_position!="right")
				_label.move(x0-_label.getExplicitOrMeasuredWidth(),_yLabel);
			else _label.move(x0,_yLabel);			
		}
		
		public function set date(x:Date):void { _date=x; }
		public function get date():Date { return _date; }
		public function set labelText(str:String):void { _labelText=str; }
		public function get labelText():String { return _labelText; }
		public function set yLabel(y:Number):void { _yLabel=y; }
		public function get yLabel():Number { return _yLabel; }
		public function set position(str:String):void { _position=str; }
		public function get position():String { return _position; }		
		public function set color(c:Number):void { _color=c; }
		public function get color():Number { return _color; }
	}
}
canuzzi is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:25 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.