index.js 12 KB

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