{"id":445,"date":"2016-02-10T22:52:40","date_gmt":"2016-02-10T14:52:40","guid":{"rendered":"http:\/\/www.hightopo.com\/blog\/?p=445"},"modified":"2016-02-19T10:46:11","modified_gmt":"2016-02-19T02:46:11","slug":"%e7%99%be%e5%ba%a6%e5%9c%b0%e5%9b%be%e3%80%81echarts%e6%95%b4%e5%90%88ht-for-web%e7%bd%91%e7%bb%9c%e6%8b%93%e6%89%91%e5%9b%be%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.hightopo.com\/blog\/445.html","title":{"rendered":"\u767e\u5ea6\u5730\u56fe\u3001ECharts\u6574\u5408HT for Web\u7f51\u7edc\u62d3\u6251\u56fe\u5e94\u7528"},"content":{"rendered":"<p>\u5728ECharts\u7684Demo\u4e2d\u770b\u5230\u4e86\u6709\u5173\u7a7a\u6c14\u8d28\u91cf\u7684\u76f8\u5173\u62a5\u8868\u5e94\u7528\uff0c\u5c31\u60f3\u5c06\u767e\u5ea6\u5730\u56fe\u3001ECharts\u548cHT for Web\u4e09\u8005\u7ed3\u5408\u8d77\u6765\u4e5f\u505a\u4e00\u4e2a\u7c7b\u4f3c\u7a7a\u6c14\u8d28\u91cf\u62a5\u544a\u7684\u62a5\u8868+\u62d3\u6251\u56fe\u5e94\u7528\uff0c\u4e8e\u662f\u6709\u4e86\u4e0b\u9762\u7684Demo\uff1a<\/p>\n<p><a href=\"http:\/\/www.hightopo.com\/demo\/blog_baidu_20150928\/ht-baidu.html\">http:\/\/www.hightopo.com\/demo\/blog_baidu_20150928\/ht-baidu.html<\/a><\/p>\n<p><img alt=\"\" src=\"http:\/\/images.cnitblog.com\/blog2015\/591709\/201503\/230146593649858.gif\" \/><\/p>\n<p>\u5728\u8fd9\u4e2aDemo\u4e2d\uff0c\u5c06<a href=\"http:\/\/www.hightopo.com\/\">GraphView<\/a>\u62d3\u6251\u56fe\u7ec4\u4ef6\u6dfb\u52a0\u5230\u767e\u5ea6\u5730\u56fe\u7ec4\u4ef6\u4e2d\uff0c\u8986\u76d6\u5728\u767e\u5ea6\u5730\u56fe\u7ec4\u4ef6\u4e4b\u4e0a\uff0c\u5e76\u4e14\u5728\u767e\u5ea6\u5730\u56fe\u7ec4\u4ef6\u4e0a\u548cGraphView\u62d3\u6251\u56fe\u7ec4\u4ef6\u4e0a\u5206\u522b\u6dfb\u52a0\u4e8b\u4ef6\u76d1\u542c\uff0c\u76f8\u4e92\u540c\u6b65\u7ecf\u7eac\u5ea6\u548c\u5c4f\u5e55\u4f4d\u7f6e\u4fe1\u606f\uff0c\u4ece\u800c\u6765\u63a7\u5236\u62d3\u6251\u56fe\u4e0a\u7684\u7ec4\u4ef6\u4f4d\u7f6e\u56fa\u5b9a\u5728\u5730\u56fe\u4e0a\uff0c\u5e76\u5728\u8282\u70b9\u548c\u8282\u70b9\u4e4b\u95f4\u7684\u8fde\u7ebf\u4e0a\u52a0\u4e0a\u4e86\u6d41\u52a8\u5c5e\u6027\u3002\u53f3\u4e0b\u89d2\u7684\u56fe\u6807\u6846\u662f\u91c7\u7528<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u7684Panel\u9762\u677f\u7ec4\u4ef6\u7ed3\u5408ECharts\u56fe\u8868\u7ec4\u4ef6\u5b8c\u6210\u7684\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u770b\u770b\u5177\u4f53\u7684\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n<p>1.\u767e\u5ea6\u5730\u56fe\u662f\u5982\u4f55\u4e0eHT for Web\u7ec4\u4ef6\u7ed3\u5408\u7684\uff1b<\/p>\n<div>\n<pre>map = new BMap.Map(\"map\");\r\nvar view = graphView.getView();\r\nview.className = 'graphView';\r\nvar mapDiv = document.getElementById('map');\r\nmapDiv.firstChild.firstChild.appendChild(view);<\/pre>\n<\/div>\n<p>\u9996\u5148\u9700\u8981\u5728body\u4e2d\u5b58\u5728id\u4e3amap\u7684div\uff0c\u518d\u901a\u8fc7\u767e\u5ea6\u5730\u56fe\u7684api\u6765\u521b\u5efa\u4e00\u4e2amap\u5730\u56fe\u5bf9\u8c61\uff0c\u7136\u540e\u521b\u5efa<a href=\"http:\/\/www.hightopo.com\/\">GraphView<\/a>\u62d3\u6251\u56fe\u7ec4\u4ef6\uff0c\u5e76\u83b7\u53d6GraphView\u7ec4\u4ef6\u4e2d\u7684view\uff0c\u6700\u540e\u5c06view\u6dfb\u52a0\u5230id\u4e3amap\u7684div\u7684\u7b2c\u4e8c\u4ee3\u5b69\u5b50\u8282\u70b9\u4e2d\u3002\u8fd9\u65f6\u5019\u95ee\u9898\u5c31\u6765\u4e86\uff0c\u4e3a\u4ec0\u4e48\u8981\u5c06view\u6dfb\u52a0\u5230map\u7684\u7b2c\u4e8c\u4ee3\u5b69\u5b50\u8282\u70b9\u4e2d\u5462\uff0c\u5f53\u4f60\u5ba1\u67e5\u5143\u7d20\u65f6\u4f60\u4f1a\u53d1\u73b0\u8fd9\u4e2adiv\u662f\u767e\u5ea6\u5730\u56fe\u7684\u906e\u7f69\u5c42\uff0c\u5c06view\u6dfb\u52a0\u5230\u4e0a\u9762\uff0c\u4f1a\u4f7fview\u4f1a\u662f\u5728\u5730\u56fe\u7684\u9876\u5c42\u53ef\u89c1\uff0c\u4e0d\u4f1a\u88ab\u5730\u56fe\u6240\u906e\u6321\u3002<\/p>\n<p>2.\u767e\u5ea6\u5730\u56fe\u548cGraphView\u7684\u4e8b\u4ef6\u76d1\u542c\uff1b<\/p>\n<div>\n<pre>map.addEventListener('moveend', function(e){\r\n   resetPosition();\r\n});\r\nmap.addEventListener('dragend', function(e){\r\n   resetPosition();\r\n});                                \r\nmap.addEventListener('zoomend', function(e){\r\n\tresetPosition();\r\n});\r\n\r\ngraphView.handleScroll = function(){};\r\ngraphView.handlePinch = function(){};\r\n\r\nfunction resetPosition(e){\r\n\tgraphView.tx(0);\r\n\tgraphView.ty(0);\r\n\tdataModel.each(function(data){\r\n\t\tvar lonLat, position;\r\n\t\tif(data instanceof ht.HtmlNode){\r\n\t\t\tif(data.getId() != 'chartTotal') {\r\n\t\t\t\tposition = data.getHost().getPosition();\r\n\t\t\t\tposition = {x: position.x + 168, y: position.y + 158};\r\n\t\t\t\tdata.setPosition(position.x, position.y);\r\n\t\t\t}\r\n\t\t} else if(data instanceof ht.Node){\r\n\t\t\tlonLat = data.lonLat;\r\n\t\t\tposition = map.pointToPixel(lonLat);\r\n\t\t\tdata.setPosition(position.x,position.y);\r\n\t\t}\r\n\t});\r\n}<\/pre>\n<\/div>\n<p>\u9996\u5148\u76d1\u542cmap\u7684\u4e09\u4e2a\u4e8b\u4ef6\uff1amoveend\u3001\u00a0dragend\u3001\u00a0zoomend\uff0c\u8fd9\u4e09\u4e2a\u4e8b\u4ef6\u505a\u4e86\u540c\u4e00\u4ef6\u4e8b&#8211;\u4fee\u6539DataModel\u4e2d\u6240\u6709data\u7684position\u5c5e\u6027\uff0c\u8ba9\u5176\u5728\u5c4f\u5e55\u4e0a\u7684\u5750\u6807\u4e0e\u5730\u56fe\u540c\u6b65\uff0c\u7136\u540e\u5c06GraphView\u7684Scroll\u548cPinch\u4e24\u4e2a\u4e8b\u4ef6\u7684\u6267\u884c\u51fd\u6570\u8bbe\u7f6e\u4e3a\u7a7a\u51fd\u6570\uff0c\u5c31\u662f\u5f53\u76d1\u542c\u5230Scroll\u6216\u8005Pinch\u4e8b\u4ef6\u65f6\u4e0d\u505a\u4efb\u4f55\u7684\u5904\u7406\uff0c\u5c06\u8fd9\u4e24\u4e2a\u4e8b\u4ef6\u4ea4\u7ed9map\u6765\u5904\u7406\u3002<\/p>\n<p>\u5728resetPosition\u51fd\u6570\u4e2d\uff0c\u505a\u7684\u4e8b\u60c5\u5f88\u7b80\u5355\uff1a\u904d\u5386DataModel\u4e2d\u7684data\uff0c\u6839\u636e\u5b83\u4eec\u5404\u81ea\u5728\u5730\u56fe\u4e0a\u7684\u7ecf\u7eac\u5ea6\u6765\u6362\u7b97\u6210\u5c4f\u5e55\u5750\u6807\uff0c\u5e76\u5c06\u5750\u6807\u8bbe\u7f6e\u5230\u76f8\u5e94\u7684data\u4e2d\uff0c\u4ece\u800c\u8fbe\u5230<a href=\"http:\/\/www.hightopo.com\/\">GraphView<\/a>\u4e2d\u7684\u8282\u70b9\u80fd\u591f\u56fa\u5b9a\u5728\u5730\u56fe\u4e0a\u7684\u6548\u679c\u3002<\/p>\n<p><img alt=\"\" src=\"http:\/\/images.cnitblog.com\/blog2015\/591709\/201503\/230149041144837.gif\" \/><\/p>\n<p><img alt=\"\" src=\"http:\/\/images.cnitblog.com\/blog2015\/591709\/201503\/230149129899115.gif\" \/><\/p>\n<p>3.\u521b\u5efa\u53f3\u4e0b\u89d2\u7684\u56fe\u8868\u7ec4\u4ef6\uff1a<\/p>\n<div>\n<pre>ht.Chart = function(option){\r\n\tvar self = this,\r\n\t\t\tview = self._view = document.createElement('div');\r\n\tview.style.position = 'absolute';\r\n\tview.style.setProperty('box-sizing', 'border-box', null);\r\n\tself._option = option;\r\n\tself._chart = echarts.init(self.getView());\r\n\tif(option)\r\n\t\tself._chart.setOption(option);\r\n\tself._FIRST = true;\r\n};\r\nht.Default.def('ht.Chart', Object, {\r\n\tms_v: 1,\r\n\tms_fire: 1,\r\n\tms_ac: ['chart', 'option', 'isFirst', 'view'],\r\n\tvalidateImpl: function(){\r\n\t\tvar self = this,\r\n\t\t\t\tchart = self._chart;\r\n\t\tchart.resize();\r\n\t\tif(self._FIRST){\r\n\t\t\tself._FIRST = false;\r\n\t\t\tchart.restore();\r\n\t\t}\r\n\t},\r\n\tsetSize: function(w, h){\r\n\t\tvar view = this._view;\r\n\t\tview.style.width = w + 'px';\r\n\t\tview.style.height = h + 'px';\r\n\t}\r\n});\r\n\r\nfunction createPanel(title, width, height){\r\n\tchart = new ht.Chart(option);\r\n\tvar c = chart.getChart();\r\n\tc.on(echarts.config.EVENT.LEGEND_SELECTED, legendSelectedFun);\r\n\tvar chartPanel = new ht.widget.Panel({\r\n\t\ttitle: title,\r\n\t\trestoreToolTip: \"Overview\",\r\n\t\twidth: width,\r\n\t\tcontentHeight: height,\r\n\t\tnarrowWhenCollapse: true,\r\n\t\tcontent: chart,\r\n\t\texpanded: true\r\n\t});\r\n\tchartPanel.setPositionRelativeTo(\"rightBottom\");\r\n\tchartPanel.setPosition(0, 0);\r\n\tchartPanel.getView().style.margin = '10px';\r\n\r\n\tdocument.body.appendChild(chartPanel.getView());\r\n}<\/pre>\n<\/div>\n<p>\u9996\u5148\u5b9a\u4e49\u4e86ht.Chart\u7c7b\uff0c\u5e76\u5b9e\u73b0\u4e86validateImpl\u65b9\u6cd5\uff0c\u65b9\u6cd5\u4e2d\u5904\u7406\u7684\u903b\u8f91\u4e5f\u5f88\u7b80\u5355\uff1a\u5728\u6bcf\u6b21\u65b9\u6cd5\u6267\u884c\u7684\u65f6\u5019\u8c03\u7528\u56fe\u8868\u7684reset\u65b9\u6cd5\u91cd\u65b0\u8bbe\u5b9a\u56fe\u6807\u7684\u5c55\u793a\u5927\u5c0f\uff0c\u5982\u679c\u8be5\u65b9\u6cd5\u662f\u7b2c\u4e00\u6b21\u6267\u884c\u7684\u8bdd\uff0c\u5c31\u8c03\u7528\u56fe\u8868\u7684restore\u65b9\u6cd5\u5c06\u56fe\u8868\u8fd8\u539f\u4e3a\u6700\u539f\u59cb\u7684\u72b6\u6001\u3002\u4f1a\u6709\u8fd9\u6837\u7684\u8bbe\u8ba1\u662f\u56e0\u4e3aht.Chart\u7c7b\u4e2d\u7684view\u662f\u52a8\u6001\u521b\u5efa\u7684\uff0c\u5728\u6ca1\u6709\u6dfb\u52a0\u5230dom\u4e4b\u524d\u5c06\u4e00\u76f4\u5b58\u5728\u4e8e\u5185\u5b58\u4e2d\uff0c\u5728\u5185\u5b58\u4e2d\u56e0\u4e3a\u5e76\u6ca1\u6709\u6d4f\u89c8\u5668\u5bbd\u9ad8\u4fe1\u606f\uff0c\u6240\u4ee5div\u7684\u5b9e\u9645\u5bbd\u9ad8\u5747\u4e3a0\uff0c\u56e0\u6b64chart\u5c06option\u5185\u5bb9\u7ed8\u5236\u5728\u5bbd\u9ad8\u4e3a0\u7684div\u4e2d\uff0c\u5373\u4f7f\u4f60resize\u4e86chart\uff0c\u5982\u679c\u6ca1\u7528\u91cd\u7f6e\u56fe\u8868\u72b6\u6001\u7684\u8bdd\uff0c\u56fe\u8868\u72b6\u6001\u5c06\u65e0\u6cd5\u5728\u56fe\u8868\u4e0a\u6b63\u5e38\u663e\u793a\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u5c31\u662f\u521b\u5efapanel\u56fe\u8868\u7ec4\u4ef6\u4e86\uff0c\u8fd9\u662f<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u7684Panel\u7ec4\u4ef6\u7684\u57fa\u672c\u7528\u6cd5\uff0c\u5176\u4e2dcontent\u5c5e\u6027\u7684\u503c\u53ef\u4ee5\u662fHT for Web\u7684\u4efb\u4f55\u7ec4\u4ef6\u6216div\u5143\u7d20\uff0c\u5982\u679c\u662fHT fro Web\u7ec4\u4ef6\u7684\u8bdd\uff0c\u8be5\u7ec4\u4ef6\u5fc5\u987b\u5b9e\u73b0\u4e86validateImpl\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5728panel\u7684\u5c5e\u6027\u53d8\u5316\u540e\u5c06\u4f1a\u8c03\u7528content\u5bf9\u5e94\u7ec4\u4ef6\u7684validateImpl\u65b9\u6cd5\u6765\u91cd\u65b0\u5e03\u5c40\u7ec4\u4ef6\u5185\u5bb9\u3002<\/p>\n<p>4.ECharts\u548c<a href=\"http:\/\/www.hightopo.com\/\">GraphView\u62d3\u6251\u56fe\u7ec4\u4ef6<\/a>\u7684\u4ea4\u4e92\uff1a<\/p>\n<div>\n<pre>legendSelectedFun = function(param) {\r\n\tif(chart._legendSelect){\r\n\t\tdelete chart._legendSelect;\r\n\t\treturn;\r\n\t}\r\n\tconsole.info(param);\r\n\tvar id = nodeMap[param.target],\r\n\t\t\tdm = graphView.dm(),\r\n\t\t\tdata = dm.getDataById(id),\r\n\t\t\tsm = dm.sm(),\r\n\t\t\tselection = sm.getSelection();\r\n\r\n\tif(param.selected[param.target]) {\r\n\t\tsm.appendSelection([data]);\r\n\t\tif(selectionData.indexOf(param.target) &lt; 0){\r\n\t\t\tselectionData.push(param.target);\r\n\t\t}\r\n\t}else {\r\n\t\tsm.removeSelection([data]);\r\n\t\tvar index = selectionData.indexOf(param.target);\r\n\t\tif(index &gt;= 0){\r\n\t\t\tselectionData.splice(index, 1);\r\n\t\t}\r\n\t}\r\n\tsm.setSelection(selection.toArray());\r\n};\r\n\r\ngraphView.mi(function(e){\r\n\tconsole.info(e.kind, e.data);\r\n\tvar c = chart.getChart(),\r\n\t\t\tlegend = c.component.legend,\r\n\t\t\tselectedMap = legend.getSelectedMap();\r\n\r\n\tif(e.kind === 'endRectSelect'){\r\n\t\tchart._legendSelect = true;\r\n\t\tfor(var name in notes){\r\n\t\t\tlegend.setSelected(name, false);\r\n\t\t}\r\n\t\tnotes = {};\r\n\t\tgraphView.dm().sm().each(function(data){\r\n\t\t\tvar note = data.s('note');\r\n\t\t\tif(note)\r\n\t\t\t\tnotes[note] = 1;\r\n\t\t});\r\n\t\tfor(var name in notes){\r\n\t\t\tlegend.setSelected(name, true);\r\n\t\t}\r\n\t} else if(e.kind === 'clickData'){\r\n\t\tchart._legendSelect = true;\r\n\t\tvar data = e.data;\r\n\t\tif(data instanceof ht.Node){\r\n\t\t\tvar note = data.s('note');\r\n\r\n\t\t\tif(note){\r\n\t\t\t\tvar selected = legend.isSelected(note);\r\n\t\t\t\tif(selected){\r\n\t\t\t\t\tgraphView.dm().sm().removeSelection([data]);\r\n\t\t\t\t}\r\n\t\t\t\tlegend.setSelected(note, !selected);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n});<\/pre>\n<\/div>\n<p>legendSelectedFun\u51fd\u6570\u662fEChart\u56fe\u8868\u7684legend\u63d2\u4ef6\u9009\u4e2d\u4e8b\u4ef6\u76d1\u542c\uff0c\u5176\u4e2d\u5904\u7406\u7684\u903b\u8f91\u662f\uff1a\u5f53legend\u63d2\u4ef6\u4e2d\u7684\u67d0\u4e2a\u8282\u70b9\u88ab\u9009\u4e2d\u4e86\uff0c\u4e5f\u9009\u4e2d\u5728<a href=\"http:\/\/www.hightopo.com\/\">GraphView<\/a>\u62d3\u6251\u56fe\u4e2d\u5bf9\u5e94\u7684\u8282\u70b9\uff0c\u5f53\u53d6\u6d88\u9009\u4e2d\u662f\uff0c\u4e5f\u53d6\u6d88\u9009\u4e2dGraphView\u62d3\u6251\u56fe\u4e2d\u5bf9\u5e94\u7684\u8282\u70b9\u3002<\/p>\n<p>\u5728GraphView\u4e2d\u6dfb\u52a0\u4ea4\u4e92\u76d1\u542c\uff0c\u5982\u679c\u5728GraphView\u4e2d\u505a\u4e86\u6846\u9009\u64cd\u4f5c\uff0c\u5728\u6846\u9009\u7ed3\u675f\u540e\uff0c\u5c06\u539f\u672clegend\u63d2\u4ef6\u4e0a\u88ab\u9009\u4e2d\u7684\u8282\u70b9\u53d6\u6d88\u9009\u4e2d\uff0c\u7136\u540e\u518d\u83b7\u53d6\u88ab\u9009\u4e2d\u8282\u70b9\uff0c\u5e76\u5728legend\u63d2\u4ef6\u4e0a\u9009\u4e2d\u5bf9\u5e94\u8282\u70b9\uff1b\u5f53GraphView\u4e0a\u7684\u8282\u70b9\u88ab\u9009\u4e2d\uff0c\u5219\u6839\u636elegend\u63d2\u4ef6\u4e2d\u5bf9\u5e94\u8282\u70b9\u9009\u4e2d\u60c5\u51b5\u6765\u51b3\u5b9alegend\u63d2\u4ef6\u4e2d\u7684\u8282\u70b9\u548cgraphView\u4e0a\u7684\u8282\u70b9\u662f\u5426\u9009\u4e2d\u3002<\/p>\n<p>\u5728GraphView\u4ea4\u4e92\u4e2d\uff0c\u6211\u5f80chart\u5b9e\u4f8b\u4e2d\u6dfb\u52a0\u4e86_legendSelect\u53d8\u91cf\uff0c\u8be5\u53d8\u91cf\u7684\u8bbe\u5b9a\u662f\u4e3a\u4e86\u963b\u6b62\u5728GraphView\u4ea4\u4e92\u4e2d\u4fee\u6539legend\u63d2\u4ef6\u7684\u8282\u70b9\u5c5e\u6027\u540e\u56de\u8c03legendSelectedFun\u56de\u8c03\u51fd\u6570\u505a\u4fee\u6539GraphView\u4e2d\u8282\u70b9\u5c5e\u6027\u64cd\u4f5c\u3002<\/p>\n<p><a href=\"http:\/\/www.hightopo.com\/demo\/blog_baidu_20150928\/ht-baidu.html\">http:\/\/www.hightopo.com\/demo\/blog_baidu_20150928\/ht-baidu.html<\/a><\/p>\n<p><img alt=\"\" src=\"http:\/\/images.cnitblog.com\/blog2015\/591709\/201503\/230149211616778.gif\" \/><\/p>\n<p>\u4eca\u5929\u5c31\u5199\u5230\u8fd9\u5427\uff0c\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u591f\u5e2e\u5230\u90a3\u4e9b\u6709\u5730\u56fe\u3001<a href=\"http:\/\/www.hightopo.com\/\">\u62d3\u6251\u56fe<\/a>\u3001\u56fe\u8868\u76f8\u7ed3\u5408\u9700\u6c42\u7684\u670b\u53cb\uff0c\u5728\u8bbe\u8ba1\u4e0a\u53ef\u80fd\u60f3\u6cd5\u8fd8\u4e0d\u591f\u6210\u719f\uff0c\u5e0c\u671b\u5927\u5bb6\u4e0d\u541d\u8d50\u6559\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728ECharts\u7684Demo\u4e2d\u770b\u5230\u4e86\u6709\u5173\u7a7a\u6c14\u8d28\u91cf\u7684\u76f8\u5173\u62a5\u8868\u5e94\u7528\uff0c\u5c31\u60f3\u5c06\u767e\u5ea6\u5730\u56fe\u3001ECharts\u548cHT for Web\u4e09\u8005\u7ed3\u5408\u8d77\u6765\u4e5f\u505a\u4e00\u4e2a\u7c7b\u4f3c\u7a7a\u6c14\u8d28\u91cf\u62a5\u544a\u7684\u62a5\u8868+\u62d3\u6251\u56fe\u5e94\u7528\uff0c\u4e8e\u662f\u6709\u4e86\u4e0b\u9762\u7684Demo\uff1a<\/p>\n<p><a href=\"http:\/\/www.hightopo.com\/demo\/blog_baidu_20150928\/ht-baidu.html\">http:\/\/www.hightopo.com\/demo\/blog_baidu_20150928\/ht-baidu.html<\/a><\/p>\n<p><img alt=\"\" src=\"http:\/\/images.cnitblog.com\/blog2015\/591709\/201503\/230146593649858.gif\" \/><\/p>\n<p>\u5728\u8fd9\u4e2aDemo\u4e2d\uff0c\u5c06<a href=\"http:\/\/www.hightopo.com\/\">GraphView<\/a>\u62d3\u6251\u56fe\u7ec4\u4ef6\u6dfb\u52a0\u5230\u767e\u5ea6\u5730\u56fe\u7ec4\u4ef6\u4e2d\uff0c\u8986\u76d6\u5728\u767e\u5ea6\u5730\u56fe\u7ec4\u4ef6\u4e4b\u4e0a\uff0c\u5e76\u4e14\u5728\u767e\u5ea6\u5730\u56fe\u7ec4\u4ef6\u4e0a\u548cGraphView\u62d3\u6251\u56fe\u7ec4\u4ef6\u4e0a\u5206\u522b\u6dfb\u52a0\u4e8b\u4ef6\u76d1\u542c\uff0c\u76f8\u4e92\u540c\u6b65\u7ecf\u7eac\u5ea6\u548c\u5c4f\u5e55\u4f4d\u7f6e\u4fe1\u606f\uff0c\u4ece\u800c\u6765\u63a7\u5236\u62d3\u6251\u56fe\u4e0a\u7684\u7ec4\u4ef6\u4f4d\u7f6e\u56fa\u5b9a\u5728\u5730\u56fe\u4e0a\uff0c\u5e76\u5728\u8282\u70b9\u548c\u8282\u70b9\u4e4b\u95f4\u7684\u8fde\u7ebf\u4e0a\u52a0\u4e0a\u4e86\u6d41\u52a8\u5c5e\u6027\u3002\u53f3\u4e0b\u89d2\u7684\u56fe\u6807\u6846\u662f\u91c7\u7528<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u7684Panel\u9762\u677f\u7ec4\u4ef6\u7ed3\u5408ECharts\u56fe\u8868\u7ec4\u4ef6\u5b8c\u6210\u7684\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u770b\u770b\u5177\u4f53\u7684\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n<p>1.\u767e\u5ea6\u5730\u56fe\u662f\u5982\u4f55\u4e0eHT for Web\u7ec4\u4ef6\u7ed3\u5408\u7684\uff1b<\/p>\n<div>\n<pre>map = new BMap.Map(\"map\");\r\nvar view = graphView.getView();\r\nview.className = 'graphView';\r\nvar mapDiv = document.getElementById('map');\r\nmapDiv.firstChild.firstChild.appendChild(view);<\/pre>\n<\/div>\n<p>\u9996\u5148\u9700\u8981\u5728body\u4e2d\u5b58\u5728id\u4e3amap\u7684div\uff0c\u518d\u901a\u8fc7\u767e\u5ea6\u5730\u56fe\u7684api\u6765\u521b\u5efa\u4e00\u4e2amap\u5730\u56fe\u5bf9\u8c61\uff0c\u7136\u540e\u521b\u5efa<a href=\"http:\/\/www.hightopo.com\/\">GraphView<\/a>\u62d3\u6251\u56fe\u7ec4\u4ef6\uff0c\u5e76\u83b7\u53d6GraphView\u7ec4\u4ef6\u4e2d\u7684view\uff0c\u6700\u540e\u5c06view\u6dfb\u52a0\u5230id\u4e3amap\u7684div\u7684\u7b2c\u4e8c\u4ee3\u5b69\u5b50\u8282\u70b9\u4e2d\u3002\u8fd9\u65f6\u5019\u95ee\u9898\u5c31\u6765\u4e86\uff0c\u4e3a\u4ec0\u4e48\u8981\u5c06view\u6dfb\u52a0\u5230map\u7684\u7b2c\u4e8c\u4ee3\u5b69\u5b50\u8282\u70b9\u4e2d\u5462\uff0c\u5f53\u4f60\u5ba1\u67e5\u5143\u7d20\u65f6\u4f60\u4f1a\u53d1\u73b0\u8fd9\u4e2adiv\u662f\u767e\u5ea6\u5730\u56fe\u7684\u906e\u7f69\u5c42\uff0c\u5c06view\u6dfb\u52a0\u5230\u4e0a\u9762\uff0c\u4f1a\u4f7fview\u4f1a\u662f\u5728\u5730\u56fe\u7684\u9876\u5c42\u53ef\u89c1\uff0c\u4e0d\u4f1a\u88ab\u5730\u56fe\u6240\u906e\u6321\u3002<\/p>\n<p>2.\u767e\u5ea6\u5730\u56fe\u548cGraphView\u7684\u4e8b\u4ef6\u76d1\u542c\uff1b<\/p>\n<div>\n<pre>map.addEventListener('moveend', function(e){\r\n   resetPosition();\r\n});\r\nmap.addEventListener('dragend', function(e){\r\n   resetPosition();\r\n});                                \r\nmap.addEventListener('zoomend', function(e){\r\n\tresetPosition();\r\n});\r\n\r\ngraphView.handleScroll = function(){};\r\ngraphView.handlePinch = function(){};\r\n\r\nfunction resetPosition(e){\r\n\tgraphView.tx(0);\r\n\tgraphView.ty(0);\r\n\tdataModel.each(function(data){\r\n\t\tvar lonLat, position;\r\n\t\tif(data instanceof ht.HtmlNode){\r\n\t\t\tif(data.getId() != 'chartTotal') {\r\n\t\t\t\tposition = data.getHost().getPosition();\r\n\t\t\t\tposition = {x: position.x + 168, y: position.y + 158};\r\n\t\t\t\tdata.setPosition(position.x, position.y);\r\n\t\t\t}\r\n\t\t} else if(data instanceof ht.Node){\r\n\t\t\tlonLat = data.lonLat;\r\n\t\t\tposition = map.pointToPixel(lonLat);\r\n\t\t\tdata.setPosition(position.x,position.y);\r\n\t\t}\r\n\t});\r\n}<\/pre>\n<\/div>\n<p>\u9996\u5148\u76d1\u542cmap\u7684\u4e09\u4e2a\u4e8b\u4ef6\uff1amoveend\u3001\u00a0dragend\u3001\u00a0zoomend\uff0c\u8fd9\u4e09\u4e2a\u4e8b\u4ef6\u505a\u4e86\u540c\u4e00\u4ef6\u4e8b&#8211;\u4fee\u6539DataModel\u4e2d\u6240\u6709data\u7684position\u5c5e\u6027\uff0c\u8ba9\u5176\u5728\u5c4f\u5e55\u4e0a\u7684\u5750\u6807\u4e0e\u5730\u56fe\u540c\u6b65\uff0c\u7136\u540e\u5c06GraphView\u7684Scroll\u548cPinch\u4e24\u4e2a\u4e8b\u4ef6\u7684\u6267\u884c\u51fd\u6570\u8bbe\u7f6e\u4e3a\u7a7a\u51fd\u6570\uff0c\u5c31\u662f\u5f53\u76d1\u542c\u5230Scroll\u6216\u8005Pinch\u4e8b\u4ef6\u65f6\u4e0d\u505a\u4efb\u4f55\u7684\u5904\u7406\uff0c\u5c06\u8fd9\u4e24\u4e2a\u4e8b\u4ef6\u4ea4\u7ed9map\u6765\u5904\u7406\u3002<\/p>\n<p>\u5728resetPosition\u51fd\u6570\u4e2d\uff0c\u505a\u7684\u4e8b\u60c5\u5f88\u7b80\u5355\uff1a\u904d\u5386DataModel\u4e2d\u7684data\uff0c\u6839\u636e\u5b83\u4eec\u5404\u81ea\u5728\u5730\u56fe\u4e0a\u7684\u7ecf\u7eac\u5ea6\u6765\u6362\u7b97\u6210\u5c4f\u5e55\u5750\u6807\uff0c\u5e76\u5c06\u5750\u6807\u8bbe\u7f6e\u5230\u76f8\u5e94\u7684data\u4e2d\uff0c\u4ece\u800c\u8fbe\u5230<a href=\"http:\/\/www.hightopo.com\/\">GraphView<\/a>\u4e2d\u7684\u8282\u70b9\u80fd\u591f\u56fa\u5b9a\u5728\u5730\u56fe\u4e0a\u7684\u6548\u679c\u3002<\/p>\n<p><img alt=\"\" src=\"http:\/\/images.cnitblog.com\/blog2015\/591709\/201503\/230149041144837.gif\" \/><\/p>\n<p><img alt=\"\" src=\"http:\/\/images.cnitblog.com\/blog2015\/591709\/201503\/230149129899115.gif\" \/><\/p>\n<p>3.\u521b\u5efa\u53f3\u4e0b\u89d2\u7684\u56fe\u8868\u7ec4\u4ef6\uff1a<\/p>\n<div>\n<pre>ht.Chart = function(option){\r\n\tvar self = this,\r\n\t\t\tview = self._view = document.createElement('div');\r\n\tview.style.position = 'absolute';\r\n\tview.style.setProperty('box-sizing', 'border-box', null);\r\n\tself._option = option;\r\n\tself._chart = echarts.init(self.getView());\r\n\tif(option)\r\n\t\tself._chart.setOption(option);\r\n\tself._FIRST = true;\r\n};\r\nht.Default.def('ht.Chart', Object, {\r\n\tms_v: 1,\r\n\tms_fire: 1,\r\n\tms_ac: ['chart', 'option', 'isFirst', 'view'],\r\n\tvalidateImpl: function(){\r\n\t\tvar self = this,\r\n\t\t\t\tchart = self._chart;\r\n\t\tchart.resize();\r\n\t\tif(self._FIRST){\r\n\t\t\tself._FIRST = false;\r\n\t\t\tchart.restore();\r\n\t\t}\r\n\t},\r\n\tsetSize: function(w, h){\r\n\t\tvar view = this._view;\r\n\t\tview.style.width = w + 'px';\r\n\t\tview.style.height = h + 'px';\r\n\t}\r\n});\r\n\r\nfunction createPanel(title, width, height){\r\n\tchart = new ht.Chart(option);\r\n\tvar c = chart.getChart();\r\n\tc.on(echarts.config.EVENT.LEGEND_SELECTED, legendSelectedFun);\r\n\tvar chartPanel = new ht.widget.Panel({\r\n\t\ttitle: title,\r\n\t\trestoreToolTip: \"Overview\",\r\n\t\twidth: width,\r\n\t\tcontentHeight: height,\r\n\t\tnarrowWhenCollapse: true,\r\n\t\tcontent: chart,\r\n\t\texpanded: true\r\n\t});\r\n\tchartPanel.setPositionRelativeTo(\"rightBottom\");\r\n\tchartPanel.setPosition(0, 0);\r\n\tchartPanel.getView().style.margin = '10px';\r\n\r\n\tdocument.body.appendChild(chartPanel.getView());\r\n}<\/pre>\n<\/div>\n<p>\u9996\u5148\u5b9a\u4e49\u4e86ht.Chart\u7c7b\uff0c\u5e76\u5b9e\u73b0\u4e86validateImpl\u65b9\u6cd5\uff0c\u65b9\u6cd5\u4e2d\u5904\u7406\u7684\u903b\u8f91\u4e5f\u5f88\u7b80\u5355\uff1a\u5728\u6bcf\u6b21\u65b9\u6cd5\u6267\u884c\u7684\u65f6\u5019\u8c03\u7528\u56fe\u8868\u7684reset\u65b9\u6cd5\u91cd\u65b0\u8bbe\u5b9a\u56fe\u6807\u7684\u5c55\u793a\u5927\u5c0f\uff0c\u5982\u679c\u8be5\u65b9\u6cd5\u662f\u7b2c\u4e00\u6b21\u6267\u884c\u7684\u8bdd\uff0c\u5c31\u8c03\u7528\u56fe\u8868\u7684restore\u65b9\u6cd5\u5c06\u56fe\u8868\u8fd8\u539f\u4e3a\u6700\u539f\u59cb\u7684\u72b6\u6001\u3002\u4f1a\u6709\u8fd9\u6837\u7684\u8bbe\u8ba1\u662f\u56e0\u4e3aht.Chart\u7c7b\u4e2d\u7684view\u662f\u52a8\u6001\u521b\u5efa\u7684\uff0c\u5728\u6ca1\u6709\u6dfb\u52a0\u5230dom\u4e4b\u524d\u5c06\u4e00\u76f4\u5b58\u5728\u4e8e\u5185\u5b58\u4e2d\uff0c\u5728\u5185\u5b58\u4e2d\u56e0\u4e3a\u5e76\u6ca1\u6709\u6d4f\u89c8\u5668\u5bbd\u9ad8\u4fe1\u606f\uff0c\u6240\u4ee5div\u7684\u5b9e\u9645\u5bbd\u9ad8\u5747\u4e3a0\uff0c\u56e0\u6b64chart\u5c06option\u5185\u5bb9\u7ed8\u5236\u5728\u5bbd\u9ad8\u4e3a0\u7684div\u4e2d\uff0c\u5373\u4f7f\u4f60resize\u4e86chart\uff0c\u5982\u679c\u6ca1\u7528\u91cd\u7f6e\u56fe\u8868\u72b6\u6001\u7684\u8bdd\uff0c\u56fe\u8868\u72b6\u6001\u5c06\u65e0\u6cd5\u5728\u56fe\u8868\u4e0a\u6b63\u5e38\u663e\u793a\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u5c31\u662f\u521b\u5efapanel\u56fe\u8868\u7ec4\u4ef6\u4e86\uff0c\u8fd9\u662f<a href=\"http:\/\/www.hightopo.com\/\">HT for Web<\/a>\u7684Panel\u7ec4\u4ef6\u7684\u57fa\u672c\u7528\u6cd5\uff0c\u5176\u4e2dcontent\u5c5e\u6027\u7684\u503c\u53ef\u4ee5\u662fHT for Web\u7684\u4efb\u4f55\u7ec4\u4ef6\u6216div\u5143\u7d20\uff0c\u5982\u679c\u662fHT fro Web\u7ec4\u4ef6\u7684\u8bdd\uff0c\u8be5\u7ec4\u4ef6\u5fc5\u987b\u5b9e\u73b0\u4e86validateImpl\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5728panel\u7684\u5c5e\u6027\u53d8\u5316\u540e\u5c06\u4f1a\u8c03\u7528content\u5bf9\u5e94\u7ec4\u4ef6\u7684validateImpl\u65b9\u6cd5\u6765\u91cd\u65b0\u5e03\u5c40\u7ec4\u4ef6\u5185\u5bb9\u3002<\/p>\n<p>4.ECharts\u548c<a href=\"http:\/\/www.hightopo.com\/\">GraphView\u62d3\u6251\u56fe\u7ec4\u4ef6<\/a>\u7684\u4ea4\u4e92\uff1a<\/p>\n<div>\n<pre>legendSelectedFun = function(param) {\r\n\tif(chart._legendSelect){\r\n\t\tdelete chart._legendSelect;\r\n\t\treturn;\r\n\t}\r\n\tconsole.info(param);\r\n\tvar id = nodeMap[param.target],\r\n\t\t\tdm = graphView.dm(),\r\n\t\t\tdata = dm.getDataById(id),\r\n\t\t\tsm = dm.sm(),\r\n\t\t\tselection = sm.getSelection();\r\n\r\n\tif(param.selected[param.target]) {\r\n\t\tsm.appendSelection([data]);\r\n\t\tif(selectionData.indexOf(param.target) &lt; 0){\r\n\t\t\tselectionData.push(param.target);\r\n\t\t}\r\n\t}else {\r\n\t\tsm.removeSelection([data]);\r\n\t\tvar index = selectionData.indexOf(param.target);\r\n\t\tif(index &gt;= 0){\r\n\t\t\tselectionData.splice(index, 1);\r\n\t\t}\r\n\t}\r\n\tsm.setSelection(selection.toArray());\r\n};\r\n\r\ngraphView.mi(function(e){\r\n\tconsole.info(e.kind, e.data);\r\n\tvar c = chart.getChart(),\r\n\t\t\tlegend = c.component.legend,\r\n\t\t\tselectedMap = legend.getSelectedMap();\r\n\r\n\tif(e.kind === 'endRectSelect'){\r\n\t\tchart._legendSelect = true;\r\n\t\tfor(var name in notes){\r\n\t\t\tlegend.setSelected(name, false);\r\n\t\t}\r\n\t\tnotes = {};\r\n\t\tgraphView.dm().sm().each(function(data){\r\n\t\t\tvar note = data.s('note');\r\n\t\t\tif(note)\r\n\t\t\t\tnotes[note] = 1;\r\n\t\t});\r\n\t\tfor(var name in notes){\r\n\t\t\tlegend.setSelected(name, true);\r\n\t\t}\r\n\t} else if(e.kind === 'clickData'){\r\n\t\tchart._legendSelect = true;\r\n\t\tvar data = e.data;\r\n\t\tif(data instanceof ht.Node){\r\n\t\t\tvar note = data.s('note');\r\n\r\n\t\t\tif(note){\r\n\t\t\t\tvar selected = legend.isSelected(note);\r\n\t\t\t\tif(selected){\r\n\t\t\t\t\tgraphView.dm().sm().removeSelection([data]);\r\n\t\t\t\t}\r\n\t\t\t\tlegend.setSelected(note, !selected);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n});<\/pre>\n<\/div>\n<p>legendSelectedFun\u51fd\u6570\u662fEChart\u56fe\u8868\u7684legend\u63d2\u4ef6\u9009\u4e2d\u4e8b\u4ef6\u76d1\u542c\uff0c\u5176\u4e2d\u5904\u7406\u7684\u903b\u8f91\u662f\uff1a\u5f53legend\u63d2\u4ef6\u4e2d\u7684\u67d0\u4e2a\u8282\u70b9\u88ab\u9009\u4e2d\u4e86\uff0c\u4e5f\u9009\u4e2d\u5728<a href=\"http:\/\/www.hightopo.com\/\">GraphView<\/a>\u62d3\u6251\u56fe\u4e2d\u5bf9\u5e94\u7684\u8282\u70b9\uff0c\u5f53\u53d6\u6d88\u9009\u4e2d\u662f\uff0c\u4e5f\u53d6\u6d88\u9009\u4e2dGraphView\u62d3\u6251\u56fe\u4e2d\u5bf9\u5e94\u7684\u8282\u70b9\u3002<\/p>\n<p>\u5728GraphView\u4e2d\u6dfb\u52a0\u4ea4\u4e92\u76d1\u542c\uff0c\u5982\u679c\u5728GraphView\u4e2d\u505a\u4e86\u6846\u9009\u64cd\u4f5c\uff0c\u5728\u6846\u9009\u7ed3\u675f\u540e\uff0c\u5c06\u539f\u672clegend\u63d2\u4ef6\u4e0a\u88ab\u9009\u4e2d\u7684\u8282\u70b9\u53d6\u6d88\u9009\u4e2d\uff0c\u7136\u540e\u518d\u83b7\u53d6\u88ab\u9009\u4e2d\u8282\u70b9\uff0c\u5e76\u5728legend\u63d2\u4ef6\u4e0a\u9009\u4e2d\u5bf9\u5e94\u8282\u70b9\uff1b\u5f53GraphView\u4e0a\u7684\u8282\u70b9\u88ab\u9009\u4e2d\uff0c\u5219\u6839\u636elegend\u63d2\u4ef6\u4e2d\u5bf9\u5e94\u8282\u70b9\u9009\u4e2d\u60c5\u51b5\u6765\u51b3\u5b9alegend\u63d2\u4ef6\u4e2d\u7684\u8282\u70b9\u548cgraphView\u4e0a\u7684\u8282\u70b9\u662f\u5426\u9009\u4e2d\u3002<\/p>\n<p>\u5728GraphView\u4ea4\u4e92\u4e2d\uff0c\u6211\u5f80chart\u5b9e\u4f8b\u4e2d\u6dfb\u52a0\u4e86_legendSelect\u53d8\u91cf\uff0c\u8be5\u53d8\u91cf\u7684\u8bbe\u5b9a\u662f\u4e3a\u4e86\u963b\u6b62\u5728GraphView\u4ea4\u4e92\u4e2d\u4fee\u6539legend\u63d2\u4ef6\u7684\u8282\u70b9\u5c5e\u6027\u540e\u56de\u8c03legendSelectedFun\u56de\u8c03\u51fd\u6570\u505a\u4fee\u6539GraphView\u4e2d\u8282\u70b9\u5c5e\u6027\u64cd\u4f5c\u3002<\/p>\n<p><a href=\"http:\/\/www.hightopo.com\/demo\/blog_baidu_20150928\/ht-baidu.html\">http:\/\/www.hightopo.com\/demo\/blog_baidu_20150928\/ht-baidu.html<\/a><\/p>\n<p><img alt=\"\" src=\"http:\/\/images.cnitblog.com\/blog2015\/591709\/201503\/230149211616778.gif\" \/><\/p>\n<p>\u4eca\u5929\u5c31\u5199\u5230\u8fd9\u5427\uff0c\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u591f\u5e2e\u5230\u90a3\u4e9b\u6709\u5730\u56fe\u3001<a href=\"http:\/\/www.hightopo.com\/\">\u62d3\u6251\u56fe<\/a>\u3001\u56fe\u8868\u76f8\u7ed3\u5408\u9700\u6c42\u7684\u670b\u53cb\uff0c\u5728\u8bbe\u8ba1\u4e0a\u53ef\u80fd\u60f3\u6cd5\u8fd8\u4e0d\u591f\u6210\u719f\uff0c\u5e0c\u671b\u5927\u5bb6\u4e0d\u541d\u8d50\u6559\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/445"}],"collection":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/comments?post=445"}],"version-history":[{"count":6,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/445\/revisions"}],"predecessor-version":[{"id":452,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/posts\/445\/revisions\/452"}],"wp:attachment":[{"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/media?parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/categories?post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hightopo.com\/blog\/wp-json\/wp\/v2\/tags?post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}