感谢原作者分享: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. Common Linux log files name and usage--reference

    reference:http://www.coolcoder.in/2013/12/common-linux-log-files-name-and-usage.html if you spend lo ...

  2. 编写who命令:文件操作,缓冲区与联机帮助

    最近阅读UULP(Understanding Unix/Linux Programming),按照书中介绍对Unix/Linux系统编程进行学习梳理,总结如下. 1. who命令能做什么 who命令用 ...

  3. LeetCode5 Longest Palindromic Substring

    题意: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...

  4. html元素英文含义

    常用html标签的英语全称及简单功能描述 <a>:anchor 定义锚 <abbr>:abbreviation 定义缩写 <acronym>: 定义只取消首字母的缩 ...

  5. .net对各表的操作详细到字段的更改记录的日志

    存入数据库中,目前的字段包括操作人,操作时间,sql语句,被修改的字段,字段原值,操作人的身份. /// <summary> /// 添加操作日志 /// </summary> ...

  6. ASP.NET页面与IIS底层交互和工作原理详解(第二回)

    引言 在 Part.1 Http请求处理流程 一文中,我们了解了Http请求的处理过程以及其它一些运作原理.我们知道Http管道中有两个可用接口,一个是IHttpHandler,一个是IHttpMod ...

  7. 常用排序算法之JavaScript实现

    1.插入排序 1)算法简介 插入排序(Insertion-Sort)的算法描述是一种简单直观的排序算法.它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从 后向前扫描,找到相应位置并插入 ...

  8. [转]c# xml.Load() locking file on disk causing errors

    本文转自:http://stackoverflow.com/questions/1812598/c-sharp-xml-load-locking-file-on-disk-causing-errors ...

  9. CentOS服务器的16个监控命令

    你可以通过图形化用户界面(GUI)程序来获取这些外壳命令提供的大量信息,具体取决于使用哪一种Linux发行版.比如说,SUSE Linux就有一款出色的.图形化配置和管理工具YaST,KDE的KDE ...

  10. 查询score中选学多门课程的同学中分数为非最高分成绩的记录。

    20.查询score中选学多门课程的同学中分数为非最高分成绩的记录. select * from score a where sno in ( select sno from score group ...