chartsJs.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. import jnpf from '@/utils/jnpf'
  2. import {
  3. geojson,
  4. getAtlas
  5. } from '@/api/portal/portal.js'
  6. import {
  7. getDataInterfaceRes
  8. } from '@/api/common'
  9. let timer;
  10. export default {
  11. data() {
  12. return {
  13. show: false,
  14. mapData: [],
  15. mapList: [],
  16. mapType: '',
  17. markPoints: [],
  18. pointLoading: false,
  19. opts: {
  20. update: true,
  21. fontSize: 10,
  22. padding: [40, 15, 30, 15],
  23. extra: {
  24. map: {
  25. mercator: true,
  26. },
  27. },
  28. },
  29. regionStep: [],
  30. stepMapList: [],
  31. option: {}
  32. }
  33. },
  34. created() {
  35. this.init()
  36. if (this.config.dataType === 'dynamic') {
  37. uni.$off('proRefresh')
  38. uni.$on('proRefresh', () => {
  39. this.handelChart()
  40. })
  41. }
  42. },
  43. methods: {
  44. init() {
  45. if (timer) clearInterval(timer)
  46. this.handelChart()
  47. if (!this.config.allRefresh.autoRefresh && this.config?.refresh?.autoRefresh) {
  48. timer = setInterval(this.handelChart, this.config.refresh.autoRefreshTime * 60000)
  49. }
  50. },
  51. async handelChart() {
  52. if (this.config.dataType === 'dynamic') {
  53. if (!this.config.propsApi) return
  54. const query = {
  55. paramList: this.config.templateJson
  56. };
  57. getDataInterfaceRes(this.config.propsApi, query).then(res => {
  58. this.config.option.defaultValue = this.handleMappingConfig(res.data, this.config)
  59. this.handleAttrs()
  60. })
  61. } else {
  62. this.handleAttrs()
  63. }
  64. },
  65. // 处理字段映射
  66. handleMappingConfig(resultData, config) {
  67. let defaultValue = undefined
  68. if (['rankList', 'barChart', 'pieChart', 'tableList'].includes(this.config.jnpfKey)) {
  69. defaultValue = this.config.option.defaultValue || []
  70. }
  71. let mappingConfig = config.mappingConfig
  72. let result = []
  73. resultData.length && resultData.forEach(data => {
  74. let temp = {}
  75. for (let item of mappingConfig) {
  76. if (item.field === '系列') {
  77. temp['type'] = item.value ? data[item.value] : data['type']
  78. }
  79. if (item.field === '维度') {
  80. temp['name'] = item.value ? data[item.value] : data['name']
  81. }
  82. if (item.field === '数值') {
  83. temp['value'] = item.value ? data[item.value] : data['value']
  84. }
  85. if (item.field === '最大值') {
  86. temp['max'] = item.value ? data[item.value] : data['max']
  87. }
  88. if (item.field === '时间戳') {
  89. temp['timestamp'] = item.value ? data[item.value] : data['timestamp']
  90. }
  91. if (item.field === '经度') {
  92. temp['long'] = item.value ? data[item.value] : data['long']
  93. }
  94. if (item.field === '纬度') {
  95. temp['lat'] = item.value ? data[item.value] : data['lat']
  96. }
  97. }
  98. result.push(temp)
  99. })
  100. return result
  101. },
  102. handleParam(e) {
  103. let jnpfKey = this.config.jnpfKey
  104. let item = {}
  105. let choose = e.opts.series && e.opts.series[0]
  106. let chooseIndex = e.currentIndex['index']
  107. let name = ''
  108. let type = ''
  109. let value = ''
  110. if (jnpfKey === "barChart") {
  111. name = e.opts.categories[chooseIndex]
  112. value = choose.data[chooseIndex]
  113. type = choose.name
  114. }
  115. if (jnpfKey === "pieChart") {
  116. name = choose.name
  117. value = choose.data
  118. let series = this.option.chartData.series && this.option.chartData.series[0]
  119. type = series.name
  120. }
  121. if (jnpfKey === "lineChart") {
  122. name = e.opts.categories[chooseIndex]
  123. value = choose.data[chooseIndex]
  124. type = choose.name
  125. }
  126. if (jnpfKey === "radarChart") {
  127. chooseIndex = e.currentIndex
  128. name = e.opts.categories[chooseIndex]
  129. value = choose.data[chooseIndex]
  130. type = choose.name
  131. }
  132. if (jnpfKey === "mapChart" && choose.properties.childrenNum == 0) {
  133. name = choose.properties.name
  134. item.long = choose.properties.center[0]
  135. item.lat = choose.properties.center[1]
  136. }
  137. if (chooseIndex < 0 && jnpfKey !== "mapChart") return
  138. if (jnpfKey === "mapChart" && choose.properties.childrenNum != 0) return
  139. item.name = name
  140. item.value = value
  141. item.type = type
  142. item.urlAddress = this.config.option.urlAddress
  143. this.jnpf.solveAddressParam(item, this.config)
  144. this.jnpf.jumpLink(item.urlAddress)
  145. },
  146. handleAttrs() {
  147. let chartTitle = {
  148. titleText: this.config.option.titleText, //主标题
  149. titleTextStyleColor: this.config.option.titleTextStyleColor, //主标题字体颜色
  150. titleTextStyleFontSize: this.config.option.titleTextStyleFontSize * 2 + 'rpx', //主标题字体大小[12-25px]
  151. titleTextStyleFontWeight: this.config.option.titleTextStyleFontWeight ? 700 : 0, //主标题是否加粗
  152. titleLeft: this.config.option.titleLeft === 'left' ? 'flex-start' : this.config.option
  153. .titleLeft === 'right' ? 'flex-end' : 'center', //主子标题位置[left,center,right]
  154. titleBgColor: this.config.option.titleBgColor, //主子标题背景色[rgba(),#303133]
  155. // 图表副标题设置
  156. titleSubtext: this.config.option.titleSubtext, //子标题
  157. titleSubtextStyleColor: this.config.option.titleSubtextStyleColor, //子标题字体颜色
  158. titleSubtextStyleFontSize: this.config.option.titleSubtextStyleFontSize * 2 +
  159. 'rpx', //子标题字体大小[12-25px]
  160. titleSubtextStyleFontWeight: this.config.option.titleSubtextStyleFontWeight ? 700 : 0, //子标题是否加粗
  161. }
  162. let defVal = this.config.option.defaultValue
  163. let chartVal = JSON.parse(JSON.stringify(defVal)) || []
  164. let typeArr = Array.from(new Set(chartVal.map((item) => item.type)))
  165. let axisData = Array.from(new Set(chartVal.map((item) => item.name)))
  166. let seriesData = []
  167. let colorList = [];
  168. let chartsType = "";
  169. let Ymin = []; //y轴最小
  170. let Ymax = []; //y轴最大
  171. let type = "";
  172. let yAxis = {};
  173. let xAxis = {};
  174. if (!['mapChart', 'customEcharts'].includes(this.config.jnpfKey)) {
  175. typeArr.forEach((title, index) => {
  176. const type = this.getType(title, this.config)
  177. let obj = {
  178. name: title,
  179. type: type
  180. }
  181. if (this.config.option.seriesLabelShow) {
  182. obj.textSize = (this.config.option.seriesLabelFontSize / 2) < 12 ? 12 : this.config
  183. .option
  184. .seriesLabelFontSize / 2
  185. obj.textColor = this.config.option.seriesLabelColor
  186. }
  187. let chartArr = chartVal.filter((item) => title === item.type)
  188. if (this.config.jnpfKey === 'barChart' || this.config.jnpfKey === 'lineChart' || this
  189. .config
  190. .jnpfKey ==
  191. 'radarChart') {
  192. obj['data'] = chartArr.map((item) => item.value)
  193. } else {
  194. obj['data'] = chartArr.map((item) => {
  195. return {
  196. value: item.value,
  197. name: item.name,
  198. }
  199. })
  200. if (this.config.option.showZero) obj['data'] = obj['data'].filter((item) => item
  201. .value != 0)
  202. this.key = +new Date
  203. }
  204. Ymin.push(Math.min(...obj['data']))
  205. Ymax.push(Math.max(...obj['data']))
  206. seriesData.push(obj);
  207. })
  208. xAxis = {
  209. disabled: !this.config.option.xAxisShow, //不绘制X轴
  210. axisLine: this.config.option.xAxisShow, //绘制坐标轴轴线
  211. axisLineColor: !this.config.option.xAxisShow ? '#fff' : this.config.option
  212. .xAxisAxisLineLineStyleColor, //坐标轴轴线颜色,默认#CCCCCC
  213. title: "", //X轴标题
  214. titleFontSize: this.config.option.xAxisNameTextStyleFontSize, //标题字体大小
  215. titleFontColor: this.config.option.xAxisNameTextStyleColor, //X轴名称字体颜色
  216. titleOffsetY: -20, //标题纵向偏移距离,负数为向上偏移,正数向下偏移
  217. titleOffsetX: -300, //标题横向偏移距离,负数为向左偏移,正数向右偏移
  218. fontSize: (this.config.option.xAxisAxisLabelTextStyleFontSize / 2) < 14 ? 14 : this.config
  219. .option
  220. .xAxisAxisLabelTextStyleFontSize / 2, //X轴标签字体大小
  221. fontColor: this.config.option.xAxisAxisLabelTextStyleColor, //X轴标签字体颜色
  222. rotateAngle: this.config.option.xAxisAxisLabelRotate, ////X轴标签角度
  223. rotateLabel: this.config.option.xAxisAxisLabelRotate > 0 ? true : false, //【旋转】数据点(刻度点)文字
  224. gridColor: this.config.option.xAxisSplitLineLineStyleColor, //纵向网格颜色,默认#CCCCCC
  225. splitNumber: 4, //X轴网格数量,纵向网格数量(竖着的)
  226. disableGrid: !this.config.option.xAxisShow ? !this.config.option.xAxisShow : !this.config
  227. .option.xAxisSplitLineShow, //不绘制纵向网格(即默认绘制网格)
  228. scrollShow: axisData.length > 5 ? true : false, //是否显示滚动条,配合拖拽滚动使用(即仅在启用 enableScroll 时有效
  229. scrollAlign: "left", //滚动条初始位置
  230. scrollColor: "#A6A6A6", //滚动条颜色,默认#A6A6A6
  231. scrollBackgroundColor: "#EFEBEF", //滚动条底部背景颜色,默认#EFEBEF
  232. itemCount: axisData.length > 5 ? 6 : 5, //单屏数据密度即图表可视区域内显示的X轴数据点数量,仅在启用enableScroll时有效
  233. };
  234. yAxis = {
  235. data: [{
  236. position: "left",
  237. title: "",
  238. min: this.config.option.styleType == 6 ? -jnpf.toRound(Math.abs(Math.min(...
  239. Ymin)
  240. .toString().length > 2 ? Math.min(...Ymin) - 200 : Math
  241. .min(
  242. ...Ymin) - 50)) : 0,
  243. max: jnpf.toRound(Math.max(...Ymax)),
  244. axisLine: true, //坐标轴轴线是否显示(数据还能显示)
  245. axisLineColor: this.config.option
  246. .yAxisAxisLineLineStyleColor, //坐标轴轴线颜色,默认#CCCCCC
  247. disabled: !this.config.option.yAxisShow, //不绘制Y轴(刻度和轴线都不绘制)
  248. fontColor: this.config.option
  249. .yAxisAxisLabelTextStyleColor, //数据点(刻度点)字体颜色,默认#666666
  250. fontSize: (this.config.option.yAxisAxisLabelTextStyleFontSize / 2) < 12 ? 12 : this
  251. .config
  252. .option.yAxisAxisLabelTextStyleFontSize / 2, //数据点(刻度点)字体颜色,默认#666666
  253. }],
  254. padding: 10, //多个Y轴间的间距
  255. gridSet: "number", //横向向网格数量类型设置,可选值,'auto','array'
  256. disableGrid: !this.config.option.yAxisSplitLineShow, //不绘制横向向网格(即默认绘制网格)
  257. splitNumber: 4, //【指定数量】的横向向网格数量,此数量与Y轴数据点是否为小数有关,如果指定了max,请指定为能被max-min整除的数值
  258. gridType: "solid", //横向向网格线型
  259. gridColor: this.config.option.yAxisSplitLineLineStyleColor, //横向网格颜色,默认#CCCCCC
  260. };
  261. this.config.option.colorList.forEach((o, i) => {
  262. if (o.color1) colorList.push(o.color1)
  263. })
  264. }
  265. let opts = {
  266. color: colorList, //主题颜色,16进制颜色格式,Array格式
  267. padding: [15, 15, 0, 15], //画布填充边距[上,右,下,左],Array格式
  268. enableScroll: axisData.length > 5 ? true :
  269. false, //开启图表可拖拽滚动,开启后ontouch需要赋值为true,X轴配置里需要配置itemCount单屏幕数据点数量
  270. dataLabel: this.config.option.seriesLabelShow, //是否显示图表区域内数据点上方的数据文案
  271. legend: {
  272. fontColor: this.config.jnpfKey === 'pieChart' ? "#666666" : "",
  273. show: this.config.option.legendShow, //是否显示图例标识
  274. position: 'top',
  275. float: 'right',
  276. fontSize: (this.config.option.legendTextStyleFontSize / 2) < 14 ? 14 : this.config.option
  277. .legendTextStyleFontSize / 2
  278. },
  279. extra: {
  280. tooltip: {
  281. showBox: this.config.option.tooltipShow, //提示语显示
  282. fontSize: (this.config.option.tooltipTextStyleFontSize / 2) < 14 ? 14 : this.config
  283. .option
  284. .tooltipTextStyleFontSize / 2, //提示语字体大小
  285. fontColor: this.config.option.tooltipTextStyleColor, //提示语字体颜色
  286. bgColor: this.config.option.tooltipBgColor || '#000000' //提示窗口的背景颜色
  287. },
  288. mix: {
  289. column: {}
  290. },
  291. column: {
  292. type: 'group',
  293. width: this.config.option.seriesBarWidth, //柱体宽度
  294. activeBgColor: "#000000",
  295. activeBgOpacity: 0.08,
  296. linearType: "none",
  297. barBorderRadius: [this.config.option.seriesItemStyleBarBorderRadius, this.config.option
  298. .seriesItemStyleBarBorderRadius, this.config.option
  299. .seriesItemStyleBarBorderRadius,
  300. this.config.option.seriesItemStyleBarBorderRadius
  301. ], //自定义4个圆角半径[左上,右上,右下,左下]
  302. seriesGap: 5, //多series每个柱子之间的间距
  303. customColor: colorList, //扩展渐变色
  304. barBorderCircle: false
  305. }
  306. }
  307. }
  308. if (this.config.jnpfKey === 'barChart') {
  309. if (this.config.option.styleType == 5 || this.config.option.styleType == 1 ||
  310. this.config.option.styleType == 4 || this.config.option.styleType == 6) {
  311. type = 'group'
  312. if (this.config.option.styleType == 6) {
  313. opts.extra.column.barBorderRadius = []
  314. // opts.extra.column.width = 50
  315. // yAxis.splitNumber = (yAxis.data[0].max / 500) + (Math.abs(yAxis.data[0].min) / 500)
  316. }
  317. } else {
  318. type = 'stack'
  319. opts.extra.mix.column = {
  320. width: this.config.option.seriesBarWidth, //柱体宽度
  321. barBorderCircle: false, //启用分组柱状图半圆边框
  322. barBorderRadius: [this.config.option.seriesItemStyleBarBorderRadius, this.config.option
  323. .seriesItemStyleBarBorderRadius, this.config.option
  324. .seriesItemStyleBarBorderRadius,
  325. this.config.option.seriesItemStyleBarBorderRadius
  326. ], //自定义4个圆角半径[左上,右上,右下,左下]
  327. }
  328. }
  329. chartsType = this.config.option.styleType == 7 ? 'mix' : 'column'
  330. opts.xAxis = {
  331. ...xAxis
  332. }
  333. opts.yAxis = {
  334. ...yAxis
  335. }
  336. opts.extra.column.type = type
  337. } else if (this.config.jnpfKey === "pieChart") {
  338. chartsType = 'pie'
  339. opts.fontColor = this.config.option.seriesLabelColor
  340. opts.fontSize = (this.config.option.seriesLabelFontSize / 2) < 14 ? 14 : this.config.option
  341. .seriesLabelFontSize / 2
  342. let pieChartObj = {
  343. borderColor: "#FFFFFF",
  344. borderWidth: 3,
  345. activeOpacity: 0.5,
  346. offsetAngle: -90,
  347. labelWidth: 15,
  348. border: false,
  349. }
  350. let pieChartObj2 = {
  351. offsetX: 0,
  352. offsetY: 0,
  353. name: "",
  354. }
  355. if (this.config.option.styleType == 1) {
  356. if (this.config.option.roseType) chartsType = 'rose'
  357. opts.extra[chartsType] = {
  358. ...pieChartObj
  359. }
  360. } else {
  361. chartsType = 'ring';
  362. opts.title = {
  363. fontSize: 15,
  364. color: "#666666",
  365. ...pieChartObj2
  366. };
  367. opts.subtitle = {
  368. fontSize: 25,
  369. color: "#7cb5ec",
  370. ...pieChartObj2
  371. }
  372. opts.extra[chartsType] = {
  373. ringWidth: 60,
  374. activeRadius: 10,
  375. ...pieChartObj
  376. }
  377. }
  378. } else if (this.config.jnpfKey === "lineChart") {
  379. chartsType = this.config.option.areaStyle ? 'area' : 'line'
  380. type = this.config.option.styleType == 2 ? 'curve' : this.config.option.styleType == 3 ? 'step' :
  381. 'straight'
  382. let lineChartObj = {
  383. type: type,
  384. width: this.config.option.seriesLineStyleWidth
  385. }
  386. opts.extra[chartsType] = {
  387. ...lineChartObj
  388. }
  389. opts.xAxis = {
  390. ...xAxis
  391. }
  392. opts.yAxis = {
  393. ...yAxis
  394. }
  395. } else if (this.config.jnpfKey === "radarChart") {
  396. chartsType = "radar";
  397. type = this.config.option.styleType == 1 ? chartsType : 'circle'
  398. opts.fontSize = (this.config.option.radarAxisNameFontSize / 2) < 14 ? 14 : this.config.option
  399. .radarAxisNameFontSize / 2
  400. opts.fontColor = this.config.option.seriesLabelColor
  401. opts.extra[chartsType] = {
  402. gridType: type,
  403. gridColor: "#CCCCCC",
  404. gridCount: 5,
  405. opacity: 0.2,
  406. max: 200,
  407. labelShow: true,
  408. border: true,
  409. max: 100,
  410. labelColor: this.config.option.radarAxisNameColor
  411. }
  412. } else {
  413. this.getAtlas()
  414. chartsType = "map";
  415. this.config.option.markPoints = []
  416. opts = {
  417. update: true,
  418. fontSize: this.config.option.geoLabelFontSize,
  419. padding: [15, 15, 30, 15],
  420. dataLabel: this.config.option.geoLabelShow,
  421. fontColor: this.config.option.geoLabelColor,
  422. extra: {
  423. tooltip: {
  424. showBox: this.config.option.tooltipShow,
  425. fontColor: this.config.option.tooltipTextStyleColor || '#000',
  426. //fontSize: this.config.option.tooltipTextStyleFontSize,
  427. bgColor: this.config.option.tooltipBgColor || '#fff',
  428. bgOpacity: 1
  429. },
  430. map: {
  431. mercator: false,
  432. border: true,
  433. borderWidth: this.config.option.geoBorderWidth / 2,
  434. borderColor: this.config.option.geoBorderColor,
  435. activeBorderColor: "#F04864",
  436. activeFillColor: "#FACC14",
  437. activeFillOpacity: 1,
  438. active: true,
  439. activeTextColor: "#FFFFFF",
  440. fillOpacity: 1
  441. },
  442. },
  443. }
  444. this.config.option.defaultValue.forEach(o => {
  445. this.config.option.markPoints.push({
  446. latitude: o.lat,
  447. longitude: o.long,
  448. name: o.name,
  449. value: o.value
  450. })
  451. })
  452. }
  453. let chartData = {
  454. categories: axisData,
  455. series: seriesData,
  456. opts,
  457. type: chartsType
  458. }
  459. if (chartsType != 'map') {
  460. if (chartTitle.titleText && chartTitle.titleSubtext) {
  461. chartData.opts.legend.padding = 50
  462. } else if (chartTitle.titleText && !chartTitle.titleSubtext) {
  463. chartData.opts.legend.padding = 30
  464. } else {
  465. chartData.opts.legend.padding = 5
  466. }
  467. }
  468. this.config.option.chartData = chartData
  469. this.config.option.chartTitle = chartTitle
  470. this.option = this.config.option
  471. this.$nextTick(() => {
  472. this.show = true
  473. this.key = +new Date()
  474. })
  475. },
  476. /* 获取地图树 */
  477. getAtlas() {
  478. getAtlas().then(res => {
  479. this.mapList = jnpf.treeToArray(res.data);
  480. this.regionStep = []
  481. this.drawChina()
  482. })
  483. },
  484. /* 获取地图数据 */
  485. drawChina(type) {
  486. if (Array.isArray(this.option.mapType) && !type) this.mapType = this.option.mapType[this.option.mapType
  487. .length - 1]
  488. geojson(this.mapType).then(res => {
  489. let series = JSON.parse(JSON.stringify(res.data.features)) || [];
  490. for (var i = 0; i < series.length; i++) {
  491. if (series[i].geometry.type === 'Polygon' && !type) {
  492. if (this.mapType == 150000) {
  493. series[i].geometry.coordinates = series[i].geometry.coordinates
  494. } else {
  495. series[i].geometry.coordinates = [series[i].geometry.coordinates]
  496. }
  497. }
  498. series[i].value = Math.floor(Math.random() * 1000)
  499. series[i].color = this.option.geoAreaColor
  500. }
  501. this.mapData = series
  502. this.stepMapList.push(this.mapData)
  503. this.option.chartData.series = series
  504. this.key = +new Date()
  505. })
  506. },
  507. /* 地图点击路径 */
  508. regionStepClick(e, index) {
  509. if (index == 0) {
  510. this.stepMapList = []
  511. this.regionStep = []
  512. for (let i = 0; i < this.mapList.length; i++) {
  513. if (this.mapList[i].enCode == this.option.mapType[this.option.mapType.length - 1]) {
  514. this.regionStep.push({
  515. name: this.mapList[i].fullName,
  516. adcode: this.mapList[i].enCode
  517. })
  518. }
  519. }
  520. this.drawChina()
  521. return
  522. }
  523. this.mapType = e.adcode
  524. this.stepMapList.splice(index + 1, this.regionStep.length - index - 1)
  525. this.regionStep.splice(index + 1, this.regionStep.length - index - 1)
  526. this.drawChina(1)
  527. },
  528. /* 地图点击 */
  529. getIndex(e) {
  530. // 处理跳转参数
  531. this.handleParam(e)
  532. let current = this.mapList.filter(o => o.enCode == this.option.mapType[this.option.mapType.length - 1])
  533. if (!this.config.option.drillDown) return
  534. let mapData = this.mapData[e.currentIndex] ? this.mapData[e.currentIndex] : []
  535. this.mapType = mapData.properties.adcode
  536. let acroutes = mapData.properties.acroutes
  537. let selectName = mapData.properties.name
  538. let adcode = mapData.properties.adcode
  539. this.regionStep.unshift({
  540. name: current[0].fullName,
  541. adcode: current[0].enCode
  542. })
  543. this.regionStep.push({
  544. name: selectName,
  545. adcode: adcode
  546. })
  547. //对象数组去重
  548. this.regionStep = this.regionStep.filter((a, b, c) => {
  549. return c.findIndex(x => x.name === a.name) === b
  550. })
  551. this.pointLoading = false
  552. this.drawChina(1)
  553. },
  554. getType(title) {
  555. if (this.config.jnpfKey == 'barChart') {
  556. if (this.config.option.styleType == 7) {
  557. const arr = this.config.option.barType.find(ele => title == ele.title)
  558. if (arr && arr.type) {
  559. if (arr.type == 'bar') return 'column'
  560. return arr.type
  561. }
  562. }
  563. return 'column'
  564. } else if (this.config.jnpfKey == 'lineChart') {
  565. return 'line'
  566. } else if (this.config.jnpfKey == 'pieChart') {
  567. return 'pie'
  568. } else {
  569. return 'radar'
  570. }
  571. },
  572. /* 设置地图点 */
  573. setPoints(e) {
  574. const mapData = e.opts.chartData.mapData;
  575. this.option.markPoints = this.option.markPoints.slice(0, this.option.appShowNumber)
  576. for (var i = 0; i < this.option.markPoints.length; i++) {
  577. const points = this.coordinateToPoint(this.option.markPoints[i].longitude, this.option.markPoints[i]
  578. .latitude, mapData
  579. .bounds,
  580. mapData.scale, mapData.xoffset, mapData.yoffset, mapData.mercator)
  581. this.option.markPoints[i].x = points.x;
  582. this.option.markPoints[i].y = points.y;
  583. }
  584. this.pointLoading = true
  585. this.$refs.charts.key = +new Date();
  586. },
  587. /* 经纬度转画布坐标 */
  588. coordinateToPoint(longitude, latitude, bounds, scale, xoffset, yoffset, mercator) {
  589. var x = longitude;
  590. var y = latitude;
  591. if (mercator == true) {
  592. x = longitude * 20037508.34 / 130;
  593. y = Math.log(Math.tan((90 + latitude) * Math.PI / 360)) / (Math.PI / 180);
  594. y = y * 20037508.34 / 180;
  595. }
  596. return {
  597. x: (x - bounds.xMin) * scale + xoffset,
  598. y: (bounds.yMax - y) * scale + yoffset
  599. };
  600. }
  601. }
  602. }