感谢原作者分享: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. debian7 更换GCC版本

    最近在编译qt,之前用的是debian6,gcc版本是gcc-4.4,当使用debian7时,编译遇到了很多跟debian6不一样的问题,debian7的默认gcc使用的是gcc-4.7,可能是编译器 ...

  2. C#分屏控件用法实例

    本文实例中的自定义类PictureBox继承于UserControl,最终实现简单的分屏功能.分享给大家供大家参考之用.具体实现代码如下: public partial class PictureCo ...

  3. BootStrap2学习日记17---导航路径和分页

    导航路径 代码: <ul class="breadcrumb"> <li><a href="#">Home</a> ...

  4. 【鬼脸原创】github搭建动态网站

    a{ color:blue; font-weight:bold; } #cnblogs_post_body ol li { list-style-type: cjk-ideographic; } p[ ...

  5. 【Mood-7】tell 2 my gf-miss u not sudden but always

    #sorry not coming 2 see u the national day holiday! I'm BULL in the land,fighting 4 u and babies!  # ...

  6. Android 拍照 代码实例

    ------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 这是我做的一个简单的利用Android手机的摄像头进行拍照的实例. 在这里我实现了基本的拍照.照片的存储 ...

  7. iOS 手势大全

    1.Touch事件 //系统自动调用 //一个UITouch代表一根手指 按住option变成两根手指 //虽然是两个手指,但只执行一次触摸事件 - (void)touchesBegan:(NSSet ...

  8. hdu-5701 中位数计数(中位数)

    题目链接: 中位数计数 Problem Description   中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均数作为中位数. 现在有nn个数,每个 ...

  9. CF 163E. e-Government ac自动机+fail树+树状数组

    E. e-Government 题目: 给出n个字符串,表示n个人名,有两种操作: ?string ,统计字符串string中出现的属于城市居民的次数. +id,把编号为id的人变为城市居民,如果已经 ...

  10. highcharts设置Area颜色透明度

    $(function () { $('#container').highcharts({ chart: { type: 'area' }, xAxis: { categories: ['Jan', ' ...