index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. import * as echarts from '../../components/ec-canvas/echarts';
  2. const app = getApp();
  3. let json = {};
  4. let chart = null;
  5. Page({
  6. data: {
  7. height: [0, 0, 0],
  8. width: 0,
  9. ec_map: {
  10. onInit: undefined,
  11. show: false
  12. },
  13. eclook: {
  14. onInit: undefined,
  15. show: false
  16. },
  17. portrait: {
  18. onInit: undefined,
  19. show: false
  20. },
  21. tabActive: 0,
  22. getData: {
  23. character: { emotion: [], sex: [], feeling: [] }
  24. },
  25. cloud: {
  26. width: 0,
  27. height: 0
  28. }
  29. },
  30. onLoad(option) {
  31. let that = this;
  32. const sys = wx.getSystemInfoSync();
  33. let h = [sys.windowHeight, 0.7 * sys.windowHeight, 0.75 * sys.windowHeight, 0.75 * sys.windowHeight]
  34. wx.showLoading()
  35. const fs = wx.getFileSystemManager();
  36. wx.downloadFile({
  37. url: app.base.url + '/chinaMap.json',
  38. success: r => {
  39. fs.readFile({
  40. filePath: r.tempFilePath,
  41. encoding: 'utf8',
  42. position: 0,
  43. success(map) {
  44. json = JSON.parse(map.data || "{}").json || {};
  45. let data = app.globalData.origin;
  46. that.setData({
  47. getData: {
  48. platform: data.platform || [],
  49. map: data.map || [],
  50. total: data.total || { all: 0, sensitive: 0 },
  51. ActivityAuthor: (data.ActivityAuthor || []).sort((a, b) => {
  52. if (!a.detailUrl) a.detailUrl = app.base.url + '/author/' + a.id + '.json';
  53. if (!b.detailUrl) b.detailUrl = app.base.url + '/author/' + b.id + '.json';
  54. return b.total - a.total
  55. }),
  56. Activity: data.Activity || [],
  57. character: data.character || { emotion: [], sex: [], feeling: [] }
  58. },
  59. ec_map: {
  60. onInit: that.initChartMap.bind(that),
  61. show: true
  62. },
  63. eclook: {
  64. onInit: that.initChartLook.bind(that),
  65. show: true
  66. },
  67. portrait: {
  68. onInit: that.initChartPortrait.bind(that),
  69. show: true
  70. },
  71. height: h,
  72. width: sys.windowWidth
  73. }, () => {
  74. wx.hideLoading()
  75. })
  76. },
  77. fail(res) {
  78. wx.hideLoading()
  79. }
  80. })
  81. },
  82. fail() {
  83. wx.hideLoading()
  84. }
  85. })
  86. },
  87. loadimg(e) {
  88. let info = wx.getSystemInfoSync();
  89. let h = e.detail.height * info.screenWidth / e.detail.width
  90. this.setData({
  91. cloud: {
  92. width: info.screenWidth,
  93. height: h
  94. }
  95. })
  96. },
  97. clickTab(e) {
  98. this.setData({
  99. tabActive: e.currentTarget.dataset.i
  100. })
  101. },
  102. initChartMap(canvas, width, height, dpr) {
  103. let D = this.data.getData || {};
  104. chart = echarts.init(canvas, null, {
  105. width: width,
  106. height: height,
  107. devicePixelRatio: dpr // new
  108. });
  109. echarts.registerMap('china', json);
  110. let max = 0;
  111. let min = Infinity;
  112. D.map.map(v => {
  113. max < v.value && (max = v.value);
  114. min > v.value && (min = v.value);
  115. })
  116. var option = {
  117. tooltip: {
  118. show: true,
  119. formatter: function (res) {
  120. if (!res.data) return ""
  121. return res.data.name + ":" + (res.data.value || 0)
  122. }
  123. },
  124. visualMap: {
  125. show: false,
  126. min,
  127. max,
  128. inRange: {
  129. color: ['rgba(118,172,255, .2)', 'orangered']
  130. }
  131. },
  132. series: [
  133. {
  134. type: "map",
  135. mapType: "china",
  136. geoIndex: 0,
  137. zppm: 1.25,
  138. label: {
  139. normal: {
  140. show: true,
  141. formatter: function (r) {
  142. let d = r.data || {}
  143. if (!d.name) return "";
  144. var out = d.value;
  145. if (out >= 100000000) {
  146. out = (out / 100000000).toFixed(2) + '亿';
  147. } else if (out >= 10000) {
  148. out = (out / 10000).toFixed(2) + '万';
  149. }
  150. return d.name + ":" + out
  151. }
  152. },
  153. emphasis: {
  154. show: false
  155. }
  156. },
  157. scaleLimit: {
  158. //滚轮缩放的极限控制
  159. min: 1.25,
  160. max: 2,
  161. },
  162. itemStyle: {
  163. normal: {
  164. borderColor: "#76acff",//每个区域的边框色
  165. areaColor: 'rgba(118,172,255, 0)'//区域背景色
  166. },
  167. },
  168. data: D.map || []
  169. }
  170. ]
  171. };
  172. chart.setOption(option);
  173. return chart;
  174. },
  175. initChartLook(canvas, width, height, dpr) {
  176. let D = this.data.getData || {};
  177. D = D.platform || [];
  178. let source = [];
  179. let pie = [];
  180. D.map(v => {
  181. if (!source[0]) {
  182. source[0] = ['product', ...(v.subGroups || []).map(val => val.groupValue)]
  183. }
  184. let item = [v.groupValue];
  185. let p = 0;
  186. (v.subGroups || []).map(val => {
  187. item.push(val.total);
  188. p += val.total;
  189. })
  190. pie.push({
  191. name: v.groupValue,
  192. value: p
  193. });
  194. source.push(item)
  195. })
  196. chart = echarts.init(canvas, null, {
  197. width: width,
  198. height: height,
  199. devicePixelRatio: dpr // new
  200. });
  201. canvas.setChart(chart);
  202. let p = 0;
  203. var option = {
  204. legend: {},
  205. tooltip: {
  206. trigger: 'axis',
  207. showContent: false
  208. },
  209. dataset: {
  210. source
  211. },
  212. xAxis: { type: 'category' },
  213. yAxis: { gridIndex: 0 },
  214. grid: [{ top: '55%' }],
  215. title: [
  216. {
  217. text: '发稿量',
  218. left: 'center',
  219. top: '10%',
  220. textStyle: {
  221. color: '#031f2d',
  222. fontSize: 12,
  223. align: 'center'
  224. }
  225. },
  226. {
  227. text: '发稿趋势图',
  228. left: 'center',
  229. top: '50%',
  230. textStyle: {
  231. color: '#031f2d',
  232. fontSize: 12,
  233. align: 'center'
  234. }
  235. },
  236. ],
  237. series: [
  238. {
  239. type: 'line', lineStyle: { width: 1 }, smooth: true, seriesLayoutBy: 'row',
  240. symbolSize: p,
  241. areaStyle: {
  242. color: new echarts.graphic.LinearGradient(
  243. 0, 0, 0, 1,
  244. [
  245. { offset: 0, color: 'rgba(84,112,198, .4)' },
  246. { offset: 1, color: 'rgba(84,112,198, 0)' },
  247. ]
  248. )
  249. }
  250. },
  251. {
  252. type: 'line', lineStyle: { width: 1 }, smooth: true, seriesLayoutBy: 'row',
  253. symbolSize: p,
  254. areaStyle: {
  255. color: new echarts.graphic.LinearGradient(
  256. 0, 0, 0, 1,
  257. [
  258. { offset: 0, color: 'rgba(145,204,117, .4)' },
  259. { offset: 1, color: 'rgba(145,204,117, 0)' },
  260. ]
  261. )
  262. }
  263. },
  264. {
  265. type: 'line', lineStyle: { width: 1 }, smooth: true, seriesLayoutBy: 'row',
  266. symbolSize: p,
  267. areaStyle: {
  268. color: new echarts.graphic.LinearGradient(
  269. 0, 0, 0, 1,
  270. [
  271. { offset: 0, color: 'rgba(250,200,88, .4)' },
  272. { offset: 1, color: 'rgba(250,200,88, 0)' },
  273. ]
  274. )
  275. }
  276. },
  277. {
  278. type: 'line', lineStyle: { width: 1 }, smooth: true, seriesLayoutBy: 'row',
  279. symbolSize: p,
  280. areaStyle: {
  281. color: new echarts.graphic.LinearGradient(
  282. 0, 0, 0, 1,
  283. [
  284. { offset: 0, color: 'rgba(238,102,102, .4)' },
  285. { offset: 1, color: 'rgba(238,102,102, 0)' },
  286. ]
  287. )
  288. }
  289. },
  290. {
  291. type: 'line', lineStyle: { width: 1 }, smooth: true, seriesLayoutBy: 'row',
  292. symbolSize: p,
  293. areaStyle: {
  294. color: new echarts.graphic.LinearGradient(
  295. 0, 0, 0, 1,
  296. [
  297. { offset: 0, color: 'rgba(115,192,222, .4)' },
  298. { offset: 1, color: 'rgba(115,192,222, 0)' },
  299. ]
  300. )
  301. }
  302. },
  303. {
  304. type: 'line', lineStyle: { width: 1 }, smooth: true, seriesLayoutBy: 'row',
  305. symbolSize: p,
  306. areaStyle: {
  307. color: new echarts.graphic.LinearGradient(
  308. 0, 0, 0, 1,
  309. [
  310. { offset: 0, color: 'rgba(59,162,114, .4)' },
  311. { offset: 1, color: 'rgba(59,162,114, 0)' },
  312. ]
  313. )
  314. }
  315. },
  316. {
  317. type: 'line', lineStyle: { width: 1 }, smooth: true, seriesLayoutBy: 'row',
  318. symbolSize: p,
  319. areaStyle: {
  320. color: new echarts.graphic.LinearGradient(
  321. 0, 0, 0, 1,
  322. [
  323. { offset: 0, color: 'rgba(252,132,82, .4)' },
  324. { offset: 1, color: 'rgba(252,132,82, 0)' },
  325. ]
  326. )
  327. }
  328. },
  329. {
  330. type: 'pie',
  331. id: 'pie1',
  332. radius: ['15%', '30%'],
  333. center: ['50%', '30%'],
  334. emphasis: { focus: 'data' },
  335. data: pie,
  336. itemStyle: {
  337. borderRadius: 3,
  338. borderColor: '#fff',
  339. borderWidth: 1
  340. },
  341. label: {
  342. formatter: '{b}: {d}%'
  343. },
  344. encode: {
  345. itemName: 'product',
  346. value: '2012',
  347. tooltip: '2012'
  348. }
  349. }
  350. ]
  351. };
  352. chart.setOption(option);
  353. return chart;
  354. },
  355. initChartPortrait(canvas, width, height, dpr) {
  356. let D = this.data.getData || { character: {} };
  357. const { emotion, feeling, sex } = D.character;
  358. chart = echarts.init(canvas, null, {
  359. width: width,
  360. height: height,
  361. devicePixelRatio: dpr // new
  362. });
  363. var option = {
  364. title: [
  365. {
  366. text: '情绪分布',
  367. left: 'center',
  368. top: 10,
  369. textStyle: {
  370. color: '#031f2d',
  371. fontSize: 12,
  372. align: 'center'
  373. }
  374. },
  375. {
  376. text: '情感属性,性别占比',
  377. left: 'center',
  378. top: '50%',
  379. textStyle: {
  380. color: '#031f2d',
  381. fontSize: 12,
  382. align: 'center'
  383. }
  384. },
  385. ],
  386. series: [
  387. {
  388. type: 'pie',
  389. id: 'pie1',
  390. radius: ['15%', '30%'],
  391. center: ['50%', '30%'],
  392. data: emotion || [],
  393. itemStyle: {
  394. borderRadius: 3,
  395. borderColor: '#fff',
  396. borderWidth: 1
  397. },
  398. label: {
  399. formatter: '{b}: {d}%'
  400. },
  401. encode: {
  402. itemName: 'product',
  403. value: '2012',
  404. tooltip: '2012'
  405. }
  406. },
  407. {
  408. type: 'pie',
  409. selectedMode: 'single',
  410. top: '55%',
  411. radius: [0, '50%'],
  412. label: {
  413. position: 'inner',
  414. formatter: "{b}\n{d}%",
  415. fontSize: 12,
  416. },
  417. labelLine: {
  418. show: false
  419. },
  420. data: sex || []
  421. },
  422. {
  423. type: 'pie',
  424. top: '55%',
  425. radius: ['60%', '75%'],
  426. labelLine: {
  427. length: 30,
  428. },
  429. label: {
  430. alignTo: 'edge',
  431. formatter: "{b}\n{d}%",
  432. minMargin: 5,
  433. edgeDistance: 20,
  434. lineHeight: 20,
  435. rich: {
  436. time: {
  437. fontSize: 10,
  438. color: '#999'
  439. }
  440. }
  441. },
  442. labelLine: {
  443. length: 15,
  444. length2: 20,
  445. maxSurfaceAngle: 80
  446. },
  447. data: feeling || []
  448. }
  449. ]
  450. };
  451. chart.setOption(option);
  452. return chart;
  453. },
  454. });