arcgis api for flex之专题图制作(饼状图,柱状图等)
最近公司给我一个任务,就是利用arcgis api for flex实现在地图上点(业务数据)直接显示饼状图以及柱状图的专题图制作,而不是通过点击点显示气泡窗口的形式来实现,这个公司已经实现了。
经过一段时间的摸索,参照一些网上资源,目前大概弄出来了,里面还有待完善的地方的。
效果图如下:

(1)Chart.mxml,主要的展示地图专题图效果的页面
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags"
pageTitle="Charts in infowindow" xmlns:symbols="com.esri.ags.symbols.*"> <fx:Style>
.chartStyle
{
borderThickness: 0;
infoPlacement: center;
backgroundAlpha: 0;
infoOffsetX: 0;
infoOffsetY: 0;
paddingLeft: 0;
paddingRight: 0;
paddingTop: 0;
paddingBottom: 0;
}
</fx:Style> <fx:Script>
<![CDATA[
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.FeatureSet;
import com.esri.ags.Graphic;
import com.esri.ags.events.MapEvent;
import com.esri.ags.tasks.QueryTask;
import com.esri.ags.tasks.supportClasses.Query; import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.AsyncResponder; protected function myMap_initializeHandler(event:MapEvent):void
{
var pie:MapPoint = new MapPoint(113.55185,22.82289);
var column:MapPoint = new MapPoint(113.59637985600011,22.758225999000047);
var bar:MapPoint = new MapPoint(113.52757794,22.84012158);
var gpie:Graphic = new Graphic(pie);
var gcolumn:Graphic = new Graphic(column);
var gbar:Graphic = new Graphic(bar);
//g.attributes = new Object();
var thematic:ArrayCollection = new ArrayCollection(
[
{ Name: "危化品1", Rate: 25 },
{ Name: "危化品2", Rate: 15 },
{ Name: "危化品3", Rate: 23 }
]); //g.attributes.thematic = thematic;
gpie.attributes = thematic;
gcolumn.attributes = thematic;
gbar.attributes = thematic; this.myGraphicsLayerpie.add(gpie);
this.myGraphicsLayercolumn.add(gcolumn);
this.myGraphicsLayerbar.add(gbar);
}
]]>
</fx:Script> <fx:Declarations>
<esri:InfoSymbol id="infoSymbolpie" infoRenderer="InfoRendererPieChart" containerStyleName="chartStyle">
</esri:InfoSymbol>
<esri:InfoSymbol id="infoSymbolcolumn" infoRenderer="InfoRendererColumnChart" containerStyleName="chartStyle">
</esri:InfoSymbol>
<esri:InfoSymbol id="infoSymbolbar" infoRenderer="InfoRendererBarChart" containerStyleName="chartStylee">
</esri:InfoSymbol>
</fx:Declarations> <esri:Map id="myMap" load="myMap_initializeHandler(event)">
<esri:extent>
<esri:Extent xmin="113.284171273203" ymin="22.6348519473499" xmax="113.774816132605" ymax="22.9103935318251">
<esri:spatialReference>
<esri:SpatialReference wkid="4326"/>
</esri:spatialReference>
</esri:Extent>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer url="http://localhost:6080/ArcGIS/rest/services/ns_new/MapServer"/>
<esri:GraphicsLayer id="myGraphicsLayercolumn" symbol="{infoSymbolcolumn}">
</esri:GraphicsLayer>
<esri:GraphicsLayer id="myGraphicsLayerpie" symbol="{infoSymbolpie}">
</esri:GraphicsLayer>
<esri:GraphicsLayer id="myGraphicsLayerbar" symbol="{infoSymbolbar}">
</esri:GraphicsLayer>
</esri:Map> </s:Application>
(2)InfoRendererBarChart.mxml、InfoRendererColumnChart.mxml、InfoRendererPieChart.mxml,分别是柱状图以及饼状图实现的页面
1.InfoRendererBarChart.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
clipAndEnableScrolling="true"
creationComplete="creationCompleteHandler()"
implements="mx.core.IDataRenderer" width="100" height="100">
<!--
This is used by the QueryResultsWithChart sample.
--> <fx:Script>
<![CDATA[
private var _data:Object; [Bindable]
// implement IDataRenderer
public function get data():Object
{
return _data;
} public function set data(value:Object):void
{
_data = value;
} private function creationCompleteHandler():void
{ } ]]>
</fx:Script>
<mx:BarChart id="columnChart" width="100%" height="100%"
dataProvider="{data}"
showDataTips="true">
<mx:series>
<mx:BarSeries id="barSeries" xField="Rate"/>
</mx:series>
<mx:verticalAxis>
<mx:CategoryAxis id="barAxis" categoryField="Name"/>
</mx:verticalAxis>
<mx:verticalAxisRenderers>
<mx:AxisRenderer axis="{barAxis}" showLabels="false"/>
</mx:verticalAxisRenderers>
</mx:BarChart> </s:VGroup>
2.InfoRendererColumnChart.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
clipAndEnableScrolling="true"
creationComplete="creationCompleteHandler()"
implements="mx.core.IDataRenderer" width="100" height="100">
<!--
This is used by the QueryResultsWithChart sample.
--> <fx:Script>
<![CDATA[
private var _data:Object; [Bindable]
// implement IDataRenderer
public function get data():Object
{
return _data;
} public function set data(value:Object):void
{
_data = value;
} private function creationCompleteHandler():void
{ }
]]>
</fx:Script>
<mx:ColumnChart id="columnChart" width="100%" height="100%"
dataProvider="{data}"
showDataTips="true">
<mx:series>
<mx:ColumnSeries id="columnSeries" yField="Rate"/>
</mx:series>
<mx:horizontalAxis>
<mx:CategoryAxis id="columnAxis" categoryField="Name"/>
</mx:horizontalAxis>
<mx:horizontalAxisRenderers>
<mx:AxisRenderer axis="{columnAxis}" showLabels="false"/>
</mx:horizontalAxisRenderers>
</mx:ColumnChart> </s:VGroup>
3.InfoRendererPieChart.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
clipAndEnableScrolling="true"
creationComplete="creationCompleteHandler()"
implements="mx.core.IDataRenderer" width="100" height="100">
<!--
This is used by the QueryResultsWithChart sample.
--> <fx:Script>
<![CDATA[
private var _data:Object; [Bindable]
// implement IDataRenderer
public function get data():Object
{
return _data;
} public function set data(value:Object):void
{
_data = value;
} private function creationCompleteHandler():void
{ } ]]>
</fx:Script> <mx:PieChart id="pieChart"
width="100%" height="100%"
dataProvider="{data}"
showDataTips="true" >
<mx:series>
<mx:PieSeries field="Rate"
labelPosition="callout"
nameField="Name">
</mx:PieSeries>
</mx:series>
</mx:PieChart> </s:VGroup>
上述的总体实现思路是这样的:核心是InfoSymbol,InfoSymbol自定义infoRenderer绑定专题图的模版,比如InfoRendererBarChart.mxml、InfoRendererColumnChart.mxml、InfoRendererPieChart.mxml;程序初始化的时候生成了一些带有统计信息的Graphic添加到地图上,这些Graphic对象的attributes属性集合来保存各个统计的对象,每个统计的对象包含两个字段:Name表示危化品名称,Rate表示占有比重,下面我们会在InfoSymbol的定义中再次看到这两个字段。当定义好这些Graphic对象以后,我们就可以把它们添加到设置了InfoSymbol符号的GraphicLayer上了。在InfoSymbol的定义中,我们可以看到,在这个InfoSymbol中添加了一个饼图组件PieChart,这个饼图的dataProvider属性绑定的是{data},它代表的其实就是Graphic对象的attributes属性。你可以简单地这样认为:InfoSymbol中的data代表的就是其对应的Graphic对象的attributes属性。其他的柱状图也是同理的。
既然在InfoSymbol中可以获得Graphic的属性信息,那么根据Graphic的属性信息来绘制不同的专题图就是水到渠成的事情了。
样式代码解析:
.chartStyle
{
borderThickness: 0; /*显示专题图的边框宽度*/
infoPlacement: center;/*显示专题图的位置,这里是中心*/
backgroundAlpha: 0;/*显示专题图的背景透明度,这里设置为0,是为了隐藏背景*/
infoOffsetX: 0;/*显示专题图的X偏移,设置0,不然会偏离原始点位置*/
infoOffsetY: 0;/*显示专题图的Y偏移,设置0,不然会偏离原始点位置*/
paddingLeft: 0;/*显示专题图的位置偏移,设置0,不然会偏离原始点位置*/
paddingRight: 0;/*显示专题图的位置偏移,设置0,不然会偏离原始点位置*/
paddingTop: 0;/*显示专题图的位置偏移,设置0,不然会偏离原始点位置*/
paddingBottom: 0;/*显示专题图的位置偏移,设置0,不然会偏离原始点位置*/
}
需要完善优化之处:目前GraphicsLayer定义了三个(pie,bar,column),然后各自绑定不同的infoSymbol(pie,bar,column)。这样显的有点冗余了,其实只要定义一个GraphicsLayer,然后动态的判断绑定的是哪个infoSymbol。
备注:
GIS技术交流QQ群:432512093
arcgis api for flex之专题图制作(饼状图,柱状图等)的更多相关文章
- ArcGIS Engine要素渲染和专题图制作(转)
摘要:Feature的常用的绘制方法包括:1.简单绘制:2.唯一值绘制/多字段唯一值绘制:3.点密度/多字段点密度绘制:4.数据分级绘制:5.质量图(饼图/直方图): 6.按比例尺渲染:7.比例符号渲 ...
- 将AE开发的专题图制作功能发布为WPS
AE开发可以定制化实现ArcGIS的地理处理功能,并实际运用于其他方面的工作,有时候我们还希望将AE开发的功能发布为网络地理信息处理服务(WPS),从而能在Web端更自由便利地调用所需要的地学处理算法 ...
- 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十)态势标绘模块
config.xml文件的配置如下: <widget label="态势标绘" icon="assets/images/impact_area_over.png&q ...
- 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(一)GIS一张图的系统开发环境以及flexviewer框架
系统的GIS功能实现是基于arcgis api for flex,首先附上系统的主界面图,接下来的是对主界面的模块功能详细讲解: 一.GIS环境软件安装 (1)arcgis desktop的安装,要是 ...
- Clustering with the ArcGIS API for Flex
Clustering is an excellent technique for visualizing lotss of point data. We've all seen application ...
- ArcGIS API for Flex实现GraphicsLayer上画点、线、面。
目的: ArcGIS API for Flex实现GraphicsLayer上画点.线.面. 准备工作: 1.这次地图数据就用Esri提供的http://server.arcgisonline.com ...
- arcgis api for flex 开发入门(一)环境搭建
http://www.cnblogs.com/wenjl520/archive/2009/06/02/1494514.html arcgis api for flex 开发入门(一)环境搭建arcgi ...
- arcgis api for js实现克里金插值渲染图--不依赖GP服务
本篇的亮点是利用kriging.js结合arcgis api for js,实现克里金插值渲染图,截图如下: 具体实现的思路如下: 1.kriging.js开源js,可以实现针对容器canvas克里金 ...
- 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十三)台风模块
config.xml文件的配置如下: <widget label="台风" icon="assets/images/typhoon.png" config ...
随机推荐
- jQuery第二篇 (帅哥)
1.1 jQuery操作DOM jQuery课程的目标:学会使用jQuery设计常见效果 选择器 基本选择器:#id ..class .element.* . 层级选择器: 空格.>.+.~ 基 ...
- The replication agent has not logged a progress message in 10 minutes.
打开Replication Monitor,在Subscription Watch List Tab中,发现有大量的status= “Performance critical” 的黄色Warning, ...
- Sql Server系列:视图
视图是数据库中的一种虚拟表,与真实的表一样,视图包含一系列带有名称的行和列数据.行和列数据用来自定义视图的查询所引用的表,并且在引用视图时动态生成. 1. 视图的概念 视图是从一个或者多个表中导出的, ...
- Web APi之捕获请求原始内容的实现方法以及接受POST请求多个参数多种解决方案(十四)
前言 我们知道在Web APi中捕获原始请求的内容是肯定是很容易的,但是这句话并不是完全正确,前面我们是不是讨论过,在Web APi中,如果对于字符串发出非Get请求我们则会出错,为何?因为Web A ...
- MVVM 开发的几种模式讨论(WPF)
在WPF系(包括SL,WP或者Win8)应用开发中,MVVM是个老生常谈的问题.初学者可能不会有感觉,但当你写一个核心逻辑能在各种平台上无缝移植,而只需改改UI的时候,那种快感是无法用语言来形容的. ...
- Office 365常见问题解答(第一期)
前不久进行的一次网络调查中,有不少朋友反馈了一些对于Office 365的实际问题,这里集中地做一个解答,请大家参考 1. Office 365的UI样式是否有开源计划 据我所知已经开源了:https ...
- Front End Developer Questions 前端开发人员问题(一)
问题来源:http://markyun.github.io/2015/Front-end-Developer-Questions/ 1.Doctype作用?严格模式与混杂模式如何区分?它们有何意义?答 ...
- Entity FrameWork 365日系列文章源码研究 (1)
By KMSFan -- 此系列的文章只作为自己的读书笔记,不纳入博客园首页. 总结的知识点: 1.DBContext 类 2.Attribute里的属性(NotNull) 3.DbContext实 ...
- Android 短信监听及用途分析
监听系统短信这个只能作为一个技术点来研究下,读者可能在工作中可能不会哦涉及到,一般的应用软件也不会有这个需求 但是作为程序员呢,多了解一下也是好的. Android 监听系统短信有什么用? 1.对系统 ...
- jQuery-1.9.1源码分析系列(十三) 位置大小操作
先列一下这些个api jQuery.fn.css (propertyName [, value ]| object )(函数用于设置或返回当前jQuery对象所匹配的元素的css样式属性值.如果需要删 ...