基于ArcGIS API for JavaScript的统计图表实现
感谢原作者分享:https://github.com/shevchenhe/ChartLayer,在使用的过程中,需要自己进行调试修改,主要还是_draw函数,不同的ArcGIS JS API函数有差异,会出错。
首先是是扩展GraphicLayer
dojo.provide("sggchart.SggChartLayer");
dojo.require("dojox.gfx");
dojo.require("esri.geometry");
dojo.require("dojo.Stateful"); dojo.declare("sggchart.SggChartLayer", esri.layers.GraphicsLayer, {
divid: null,
bindGraphicLayer:null,
constructor:function(params){
dojo.mixin(this,params);
},
setDivId: function(id) {
this.divid = id;
},
_draw: function(graphic, redraw, zoomFlag) {
var that=this;
if (!this._map) {
return;
} if (graphic instanceof sggchart.SggPieChart) {
//if (!zoomFlag) {
this._drawChart(graphic, zoomFlag);
// } else {
// dojo.connect(that.bindGraphicLayer,"onUpdateEnd",dojo.hitch(that,that._drawChart,graphic, zoomFlag)
// }
}
},
hide: function() {
var length = this.graphics.length;
var thisgraphics = this.graphics;
for (var i = 0; i < length; i++) {
if (thisgraphics[i].parentDiv) {
dojo.style(thisgraphics[i].parentDiv, {
"display": "none"
});
}
}
},
show: function() {
var length = this.graphics.length;
var thisgraphics = this.graphics;
for (var i = 0; i < length; i++) {
if (thisgraphics[i].parentDiv) {
dojo.style(thisgraphics[i].parentDiv, {
"display": ""
});
}
}
},
_onPanStartHandler: function() {
this.hide();
},
_onPanEndHandler: function() { this._refresh(false);
//this._visibilityChangeHandler(this.visible); // if (this.graphics.length) {
// this.onUpdate();
// }
},
_onZoomStartHandler:function(){
this.hide();
},
_refresh: function(redraw, zoomFlag) {
var gs = this.graphics,
il = gs.length,
i,
_draw = this._draw;
if (!redraw) {
for (i = 0; i < gs.length; i++) {
_draw(gs[i], redraw, zoomFlag);
//this.remove(gs[i]);
}
} else {
for (i = 0; i < gs.length; i++) {
_draw(gs[i], redraw, zoomFlag);
}
}
this.show();
},
_onExtentChangeHandler: function(extent, delta, levelChange, lod) {
if (levelChange) {
//summary: Redraw graphics on extent change
// var _mvr = this._map.__visibleRect,
// group = this._div;
// this._init = true; this._refresh(true, levelChange); // group.setTransform(dojox.gfx.matrix.translate({
// x: _mvr.x,
// y: _mvr.y
// })); // if (this._renderProto && group.surface.pendingRender) { // canvas
// this._dirty = true;
// } else {
// if (this.visible) {
// esri.show(group.getEventSource());
// }
// }
}
},
_drawChart: function(piegraphic, zoomFlag) {
//var bindGraphic = piegraphic.piegraphic.bindGraphic;
if (!piegraphic.bindGraphic) {
return;
}
if (zoomFlag) {
dojo.byId(this.divid).removeChild(piegraphic.parentDiv);
//dojo.connect()
//this.remove(piegraphic);
}
//var graphicDojoShapeStateful=new dojo.Stateful();
//graphicDojoShapeStateful.watch
//理论上需要利用多边形的重心的
if (piegraphic.bindGraphic.visible && piegraphic.bindGraphic._extent && (offsets = this._intersects(this._map, piegraphic.bindGraphic._extent, piegraphic.bindGraphic.geometry._originOnly))) {
if (piegraphic.bindGraphic._shape) {
var svgDojoShape = piegraphic.bindGraphic.getDojoShape();
var svgx = svgDojoShape.bbox.l;
var svgy = svgDojoShape.bbox.t;
piegraphic.divWidth = svgDojoShape.bbox.r - svgx;
piegraphic.divHeight = svgDojoShape.bbox.b - svgy;
var svgtransform = svgDojoShape.parent.matrix;
var piedivx = svgx + svgtransform.dx;
var piedivy = svgy + svgtransform.dy;
if (!piegraphic.parentDiv||zoomFlag) {
var piediv = dojo.doc.createElement("div");
dojo.style(piediv, {
"left": piedivx + "px",
"top": piedivy + "px",
"position": "absolute",
"width": piegraphic.getDivWidth() + "px",
"height": piegraphic.getDivHeight() + "px",
"margin": "0px",
"padding": "0px",
"z-index": "100"
});
debugger;
dojo.byId(this.divid).appendChild(piediv);
piegraphic._draw(piediv);
piegraphic.parentDiv = piediv;
} else if (piegraphic.parentDiv) {
dojo.style(piegraphic.parentDiv, {
"left": piedivx + "px",
"top": piedivy + "px",
"position": "absolute",
"width": piegraphic.getDivWidth() + "px",
"height": piegraphic.getDivHeight() + "px",
"margin": "0px",
"padding": "0px",
"z-index": "100"
});
}
} //var mapGraphic= esri.geometry.toMapGeometry(this._map.extent,this._map.width,this._map.height,piegraphic.bindGraphic.geometry.getExtent);
//} else if (!piegraphic.bindGraphic._shape && piegraphic.parentDiv) {
} else {
dojo.byId(this.divid).removeChild(piegraphic.parentDiv);
piegraphic.parentDiv=null;
//this.remove(piegraphic);
} }
});
然后扩展Graphic进行图表的绘制,此处使用的是dojo图表,建议使用highCharts
dojo.provide("sggchart.SggChartGraphics");
dojo.require("dojox.charting.Chart");
dojo.require("dojox.charting.plot2d.Pie");
dojo.require("dojox.charting.themes.Claro");
dojo.require("dojox.charting.themes.PlotKit.green");
dojo.require("dojox.charting.themes.Tufte");
dojo.require("dojox.charting.themes.CubanShirts");
dojo.require("dojox.charting.action2d.MoveSlice");
dojo.require("dojox.charting.action2d.Tooltip");
dojo.require("dojox.charting.widget.Legend");
//dojo.require("dojo.Stateful"); dojo.declare("sggchart.SggChartGraphics", esri.Graphic, {
bindGraphic: null,
parentDiv: null,
series: null,
id: null,
divHeight: null,
divWidth: null,
map: null,
setId: function(id) {
this.id = id;
},
setSeries: function(series) {
this.series = series;
},
setDivHeight: function(height) {
this.divHeight = height;
},
setDivWidth: function(width) {
this.divWidth = width;
},
getDivHeight: function() {
return this.divHeight;
},
getDivWidth: function() {
return this.divWidth;
},
getSeries: function() {
return this.series;
},
getId: function() {
return this.id;
},
hide: function() {
if (this.parentDiv) {
dojo.style(this.parentDiv, "display", "none");
}
},
show: function() {
if (this.parentDiv) {
dojo.style(this.parentDiv, "display", "");
}
},
_getMap: function() {
var gl = this._graphicsLayer;
return gl._map;
}
}); dojo.declare("sggchart.SggPieChart", sggchart.SggChartGraphics, {
watchobject:null,
constructor: function(graphic) {
dojo.mixin(this, {
bindGraphic: graphic
});
//var tempwatch=new dojo.Stateful();
//this.watchobject=tempwatch;
}, _draw: function(divContainer) {
var _chart = new dojox.charting.Chart(divContainer);
//var r = this.divWidth / 2;
var r=50;
var thetheme1=dojox.charting.themes.PlotKit.green;
thetheme1.chart.fill = "transparent";
thetheme1.chart.stroke = "transparent";
thetheme1.plotarea.fill = "transparent"; _chart.setTheme(thetheme1).
addPlot("default", {
type: dojox.charting.plot2d.Pie,
radius: r
}).
addSeries(this.getId(), this.getSeries());
new dojox.charting.action2d.Tooltip(_chart, "default");
new dojox.charting.action2d.MoveSlice(_chart, "default");
_chart.render();
this.chart = _chart;
}
}); /*dojo.declare("SggBarChart",SggChartGraphics,{
_draw:function(divContainer){
var _chart=new dojox.charting.Chart(divContainer); }
})*/
基于ArcGIS API for JavaScript的统计图表实现的更多相关文章
- 基于ArcGIS API for Javascript的地图编辑工具
最近工作上需要用ArcGIS API for Javascript来开发一个浏览器上使用的地图编辑工具,分享一下一些相关的开发经验. 我开发的地图编辑工具是根据ESRI提供的例子修改而来的,参考的例子 ...
- ArcGIS API for JavaScript(2)-ArcGIS Server发布要素图层服务
1.前言 上一篇该系列的文章我们主要讲了一下基础Web地图搭建,这篇我们主要讲一下ArcGIS Server发布服务,并且如何调用服务.将自己的数据加载到Web地图当中来,实现Web端浏览数据. 2. ...
- arcgis api for javascript 3.16开发(一)
原来一直都在用Flex开发arcgis的地图接口,用的时间很长,用的习惯也顺手,可Flex这个开发工具已经基本要淘汰了,并且地图借助flash的方式加载在浏览器里已经不能适应webgis的快速开发需求 ...
- ArcGIS API for JavaScript介绍
ArcGIS API for JavaScript中的类是按照模块组织的,主要包含esri.esri/geometry.esri/renderers.esri/symbols.esri/symbols ...
- ArcGIS API for JavaScript 4.2学习笔记[5] 官方API大章节概述与内容转译
内容如上,截图自ESRI官网,连接:ArcGIS API for JavaScript 4.2 [Get Started] 类似于绪论一样的东西,抽取了最需要关注的几个例子.如:加载Map和View, ...
- ArcGIS API for JavaScript 4.2学习笔记[1] 显示地图
ArcGIS API for JavaScript 4.2直接从官网的Sample中学习,API Reference也是从官网翻译理解过来,鉴于网上截稿前还没有人发布过4.2的学习笔记,我就试试吧. ...
- ArcGIS API for JavaScript 4.2学习笔记[0] AJS4.2概述、新特性、未来产品线计划与AJS笔记目录
放着好好的成熟的AJS 3.19不学,为什么要去碰乳臭未干的AJS 4.2? 4.2全线基础学习请点击[直达] 4.3及更高版本的补充学习请关注我的博客. ArcGIS API for JavaScr ...
- ArcGIS API for JavaScript 入门教程[1] 渊源
->对于萌新,你可能需要了解一下这个东西是什么 ->对于已经知道要用这个东西的开发者,你可能需要了解一下它的底层机制 不针对大牛.龟速更新ing. 转载注明出处.博客园&CSDN& ...
- ArcGIS API for JavaScript开发初探——HelloMap
1.前言 在开始ArcGIS API for JavaScript开发之前我们需要了解一些基本的知识: 1.开发工具选什么? 前端技术的开发工具选择是一个仁者见仁智者见智的问题,有人喜欢Hbuilde ...
随机推荐
- 自定义强大的C#网络操作基础类(NetHelper)
using System; using System.Text;using System.Net.Sockets;using System.Net.Mail;using System.Net; nam ...
- WPF 之 鼠标双击事件
由于WPF中没有鼠标的双击事件,因而只能通过MouseDown事件来模拟.当连续的两次MouseDown事件的时间间隔,没有超过一个设定的时间阈值时,就计算为一个双击事件,并作相应的处理. 利用WPF ...
- org.apache.solr.common.util.ContentStream.java及其实现类
org.apache.solr.common.util.ContentStream.java 主要是获取文件,URL,字节数组,字符串等的数据流.主要方法又InputStream getStream( ...
- Solr DIH dataconfig配置
1. 配置文件data-config.xml定义了数据库的基本配置,以及导出数据的映射规则,即导出数据库表中对应哪些字段的值,以及对特定字段的值做如何处理 </pre><p>& ...
- IOS 图片转换二进制 二进制转换为图片
//类方法 图片 转换为二进制 +(NSData *)Image_TransForm_Data:(UIImage *)image { NSData *imageData = UIImageJPEGRe ...
- 如何成为apple开发者???
苹果开发者帐号申请流程如下 http://www.360doc.com/content/13/1029/12/11029609_325024387.shtml 苹果开发者账号分为 个人(individ ...
- 【Shell脚本学习8】Shell特殊变量:Shell $0, $#, $*, $@, $?, $$和命令行参数
前面已经讲到,变量名只能包含数字.字母和下划线,因为某些包含其他字符的变量有特殊含义,这样的变量被称为特殊变量. 例如,$ 表示当前Shell进程的ID,即pid,看下面的代码: $echo $$ 运 ...
- onInterceptTouchEvent和onTouchEvent举例分析
首先自定义三个组件,其关系是:MyLayout在最上面,MySubLayout在MyLayout下面,MyView在MySubLayout下面. 一个点击事件进来,首先是DOWN动作,先是MyLayo ...
- iOS中通知中心NSNotificationCenter应用总结
通知中心(NSNotificationCenter)实际是在程序内部提供了一种广播机制.把接收到的消息,根据内部的消息转发表,将消息转发给需要的对象.这句话其实已经很明显的告诉我们要如何使用通知了.第 ...
- uva 11234 Expressions 表达式 建树+BFS层次遍历
题目给出一个后缀表达式,让你求从下往上的层次遍历. 思路:结构体建树,然后用数组进行BFS进行层次遍历,最后把数组倒着输出就行了. uva过了,poj老是超时,郁闷. 代码: #include < ...