<?xml version="1.0" encoding="utf-8"?>
<!--
////////////////////////////////////////////////////////////////////////////////
// 株式会社　アイエルエス
// Copyright 2008 ILS
// All Rights Reserved.
//
// NOTICE:折れ線グラフ
////////////////////////////////////////////////////////////////////////////////
-->
<GcPanel 
	xmlns="bizLibrary.sharedComponent.*"
	xmlns:mx="http://www.adobe.com/2006/mxml"
	width="{Application.application.width}"
	height="{Application.application.height}" 
	resize="true"
	creationComplete="onCreationComplete()"
	>

    <!-- データモデルの定義 -->
	
	<mx:Script>
		<![CDATA[
			import commonLibrary.sharedComponent.cmLineSeries;
			import mx.core.Application;
			import mx.controls.Image;
			import mx.charts.HitData;
			import mx.charts.DateTimeAxis;
			import mx.charts.CategoryAxis;
			import mx.charts.chartClasses.Series;
			import mx.charts.chartClasses.ChartBase;
			import mx.collections.ArrayCollection;
			import mx.events.ItemClickEvent;
			import mx.charts.series.ColumnSeries;
			import mx.charts.Legend;
			import mx.core.DragSource;
			import mx.containers.Canvas;
			import mx.charts.events.LegendMouseEvent;
			import mx.charts.LegendItem;
			import mx.controls.Alert;
			import mx.core.UIComponent;
			import mx.charts.series.LineSeries;
			import mx.managers.DragManager;
			import mx.events.DragEvent;
			import mx.managers.PopUpManager;

			//一覧情報
			[Bindable]
			public var dataModel:XML;
	        public var selData:XML;
			
			[Bindable]
			private var dataProvider:Array;

			private var lcRegionSeries:Array;

			private var chart:ChartBase;
			private var series:Series;
			
			
			/**
			 * 共通初期化処理
			 * 
			 */		
			private function onCreationComplete():void{	                
	            //外部ファイルの取込
	            getXMLFile(setChart);
			}

			/**
			 * グラフの設定
			 * 
			 */		
	        private function setChart():void{
	        	//グラフデータの設定
			    dataModel = xmlData;
				selData = XML(dataModel.data.chart);
				
				//グラフタイトルのセット
	        	lblTitle.text = dataModel.data.grapfTitle.toString();
	        	if(lblTitle.text==""){
	        		boxTitleArea.visible = false;
	        	}
	        	//X軸
	        	xAxis.title = dataModel.data.grapfXTitle.toString();
	        	//Y軸
	        	yAxis.title = dataModel.data.grapfYTitle.toString();
	        	
	        	makeChart();
	        }


			/**
			 * グラフ作成
			 * 
			 */				
			private function makeChart():void{

				lcRegion.series = null;
				lcRegionSeries = new Array;

	            lcRegion.dataProvider = selData.axis;
	            
				//名前リスト作成
	            createNameList(sortSeq(selData.item));
	
	            // Iterate over categorys and create a new series 
	            // for each one.
	            for each(var s:String in namelist) {
	                // Use all items namese category matches s.
	                var localXML:XMLList = selData.item.(name==s);
	
					//グラフのX軸、Y軸の設定
		            var localSeries:cmLineSeries = new cmLineSeries();
		            localSeries.dataProvider = localXML;
		            localSeries.yField="value";
		            localSeries.xField="category";
		            if(graphForm != ""){
		            	localSeries.form=graphForm;
		            }
	                // dataTips and Legendに表示する値を設定
	                localSeries.displayName = s;	
	                // Series オブジェクトの配列に新しいSeriesを追加する
	                lcRegionSeries.push(localSeries);
	                // グラフに新しいSeries オブジェクトの配列を追加
	                lcRegion.series = lcRegionSeries;

	            }
	            
			}
			
			
	        private function formatDataTip(hitData:HitData):String
	        {
	            var name:String = hitData.item.name;
	            var category:String = hitData.item.category;
	            var value:Number = hitData.item.value;
	            return "<b>"+name+"</b><br>"+category+"<br>"+suDisplay.format(value);
	        }
	        
            


		]]>
	</mx:Script>
	
	<mx:NumberFormatter id="suDisplay" 
		decimalSeparatorTo="."
		thousandsSeparatorTo=","
		useThousandsSeparator="true"/>
		
    <mx:VBox id="boxChart" left="0" right="0" verticalGap="0" height="100%">
	   
	    <mx:HBox id="boxTitleArea" horizontalGap="0" visible="true" >
	    	<mx:Label id="lblTitle" fontWeight="bold" paddingLeft="20" fontSize="12" />
	    </mx:HBox>
	    
	    <mx:Canvas id="cnv2" label="cv2" width="100%" height="100%"  horizontalScrollPolicy="off" verticalScrollPolicy="off">
	    	<mx:HBox width="100%" height="100%" id="lineBox" horizontalGap="0">
				<mx:LineChart id="lcRegion" width="80%" height="{cnv2.height}" 
					dataProvider="{dataProvider}"
			        paddingLeft="5" paddingRight="5"
			        showDataTips="true"
			        dataTipFunction="formatDataTip"
			        >
					<mx:horizontalAxis>
				       <mx:CategoryAxis id="xAxis" categoryField="category"/>
				    </mx:horizontalAxis>
				    <mx:verticalAxis>
				    	<mx:LinearAxis id="yAxis"/>
				    </mx:verticalAxis>
				    
					<mx:backgroundElements>
						<mx:Array>
					        <mx:GridLines direction="both">
								<mx:verticalStroke>
									<mx:Stroke weight="1" color="#CCCCCC"/>
								</mx:verticalStroke>
							</mx:GridLines>
						</mx:Array>
					</mx:backgroundElements>
					
				</mx:LineChart>
				
				<mx:HBox height="{cnv2.height}" width="20%" horizontalScrollPolicy="off">
					<mx:Legend id="legend1" dataProvider="{lcRegion}" maxWidth="180"/>
				</mx:HBox>
	    	</mx:HBox>
		</mx:Canvas>    	
    </mx:VBox>

</GcPanel>
