感谢原作者分享: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的统计图表实现的更多相关文章

  1. 基于ArcGIS API for Javascript的地图编辑工具

    最近工作上需要用ArcGIS API for Javascript来开发一个浏览器上使用的地图编辑工具,分享一下一些相关的开发经验. 我开发的地图编辑工具是根据ESRI提供的例子修改而来的,参考的例子 ...

  2. ArcGIS API for JavaScript(2)-ArcGIS Server发布要素图层服务

    1.前言 上一篇该系列的文章我们主要讲了一下基础Web地图搭建,这篇我们主要讲一下ArcGIS Server发布服务,并且如何调用服务.将自己的数据加载到Web地图当中来,实现Web端浏览数据. 2. ...

  3. arcgis api for javascript 3.16开发(一)

    原来一直都在用Flex开发arcgis的地图接口,用的时间很长,用的习惯也顺手,可Flex这个开发工具已经基本要淘汰了,并且地图借助flash的方式加载在浏览器里已经不能适应webgis的快速开发需求 ...

  4. ArcGIS API for JavaScript介绍

    ArcGIS API for JavaScript中的类是按照模块组织的,主要包含esri.esri/geometry.esri/renderers.esri/symbols.esri/symbols ...

  5. ArcGIS API for JavaScript 4.2学习笔记[5] 官方API大章节概述与内容转译

    内容如上,截图自ESRI官网,连接:ArcGIS API for JavaScript 4.2 [Get Started] 类似于绪论一样的东西,抽取了最需要关注的几个例子.如:加载Map和View, ...

  6. ArcGIS API for JavaScript 4.2学习笔记[1] 显示地图

    ArcGIS API for JavaScript 4.2直接从官网的Sample中学习,API Reference也是从官网翻译理解过来,鉴于网上截稿前还没有人发布过4.2的学习笔记,我就试试吧. ...

  7. ArcGIS API for JavaScript 4.2学习笔记[0] AJS4.2概述、新特性、未来产品线计划与AJS笔记目录

    放着好好的成熟的AJS 3.19不学,为什么要去碰乳臭未干的AJS 4.2? 4.2全线基础学习请点击[直达] 4.3及更高版本的补充学习请关注我的博客. ArcGIS API for JavaScr ...

  8. ArcGIS API for JavaScript 入门教程[1] 渊源

    ->对于萌新,你可能需要了解一下这个东西是什么 ->对于已经知道要用这个东西的开发者,你可能需要了解一下它的底层机制 不针对大牛.龟速更新ing. 转载注明出处.博客园&CSDN& ...

  9. ArcGIS API for JavaScript开发初探——HelloMap

    1.前言 在开始ArcGIS API for JavaScript开发之前我们需要了解一些基本的知识: 1.开发工具选什么? 前端技术的开发工具选择是一个仁者见仁智者见智的问题,有人喜欢Hbuilde ...

随机推荐

  1. CentOS安装某个命令的办法如locate

    在Linux使用命令时,有时候因为系统精简的原因,某些命令可能没有安装locate包,例如你要输入的命令是locate 发现没有该命令,修复办法如下: 一.使用如下命令查询缺失命令的包名 #yum l ...

  2. .NET 托管堆和垃圾回收

       托管堆基础 简述:每个程序都要使用这样或那样的资源,包括文件.内存缓冲区.屏幕空间.网络连接.....事实上,在面向对象的环境中,每个类型都代表可供程序使用的一种资源.要使用这些资源,必须为代表 ...

  3. MR 的 mapper 数量问题

    看到群里面一篇文章涨了贱识 http://www.cnblogs.com/xuxm2007/archive/2011/09/01/2162011.html 之前关注过 reduceer 的数量问题,还 ...

  4. WPF 之 左键弹出操作菜单,并禁用右键菜单

    在目前的WPF版本中,很多的控件都有一个ContextMenu的属性,可以设置组件的右键菜单,这点确实是很方便,但是有些时候我们可能会需要当单击鼠标左键才弹出这个ContextMenu,而不是单击鼠标 ...

  5. 3. Android框架和工具之 xUtils(HttpUtils)

    1. HttpUtils 作用: 支持同步,异步方式的请求: 支持大文件上传,上传大文件不会oom: 支持GET,POST,PUT,MOVE,COPY,DELETE,HEAD请求: 下载支持301/3 ...

  6. 【网络编程】之十二、wsaeventselect+线程池 服务器实现

    #include<WinSock2.h> #include<iostream> using namespace std; #pragma comment(lib, " ...

  7. 重构20-Extract Subclass(提取父类)

    当一个类中的某些方法并不是面向所有的类时,可以使用该重构将其迁移到子类中.我这里举的例子十分简单,它包含一个Registration类,该类处理与学生注册课程相关的所有信息. public class ...

  8. 一个简单的Python爬虫

    写了一个抓taobao图片的爬虫,全是用if,for,while写的,比较简陋,入门作品. 从网页http://mm.taobao.com/json/request_top_list.htm?type ...

  9. XAML设计器卡死

    在生成工程时,存在这样一个记录: “未能找到一个或多个间接引用的程序集.分析不需要这些程序集.但是,如果没有这些程序集,分析结果可能不完整”. 表现形式既不是错误,可也不是警告.之所以关注到这个问题, ...

  10. jQuery .on() 绑定事件无效

    前几天,要在移动端实现一系列的功能,用 HTML + JS. 按照以往的思路,事件绑定就直接 $(document).on "click", "selector" ...