plm前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

472 lines
14 KiB

2 years ago
  1. <template>
  2. <div class="mod-demo-echarts">
  3. <el-alert
  4. title="提示:"
  5. type="warning"
  6. :closable="false">
  7. <div slot-scope="description">
  8. <p class="el-alert__description">1. 此Demo只提供ECharts官方使用文档入门部署和体验功能具体使用请参考http://echarts.baidu.com/index.html</p>
  9. </div>
  10. </el-alert>
  11. <el-row :gutter="20">
  12. <el-col :span="24">
  13. <el-card>
  14. <div id="J_chartLineBox" class="chart-box"></div>
  15. </el-card>
  16. </el-col>
  17. <el-col :span="24">
  18. <el-card>
  19. <div id="J_chartBarBox" class="chart-box"></div>
  20. </el-card>
  21. </el-col>
  22. <el-col :span="12">
  23. <el-card>
  24. <div id="J_chartPieBox" class="chart-box"></div>
  25. </el-card>
  26. </el-col>
  27. <el-col :span="12">
  28. <el-card>
  29. <div id="J_chartScatterBox" class="chart-box"></div>
  30. </el-card>
  31. </el-col>
  32. </el-row>
  33. </div>
  34. </template>
  35. <script>
  36. import echarts from 'echarts'
  37. export default {
  38. data () {
  39. return {
  40. chartLine: null,
  41. chartBar: null,
  42. chartPie: null,
  43. chartScatter: null
  44. }
  45. },
  46. mounted () {
  47. this.initChartLine()
  48. this.initChartBar()
  49. this.initChartPie()
  50. this.initChartScatter()
  51. },
  52. activated () {
  53. // 由于给echart添加了resize事件, 在组件激活时需要重新resize绘画一次, 否则出现空白bug
  54. if (this.chartLine) {
  55. this.chartLine.resize()
  56. }
  57. if (this.chartBar) {
  58. this.chartBar.resize()
  59. }
  60. if (this.chartPie) {
  61. this.chartPie.resize()
  62. }
  63. if (this.chartScatter) {
  64. this.chartScatter.resize()
  65. }
  66. },
  67. methods: {
  68. // 折线图
  69. initChartLine () {
  70. var option = {
  71. 'title': {
  72. 'text': '折线图堆叠'
  73. },
  74. 'tooltip': {
  75. 'trigger': 'axis'
  76. },
  77. 'legend': {
  78. 'data': [ '邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎' ]
  79. },
  80. 'grid': {
  81. 'left': '3%',
  82. 'right': '4%',
  83. 'bottom': '3%',
  84. 'containLabel': true
  85. },
  86. 'toolbox': {
  87. 'feature': {
  88. 'saveAsImage': { }
  89. }
  90. },
  91. 'xAxis': {
  92. 'type': 'category',
  93. 'boundaryGap': false,
  94. 'data': [ '周一', '周二', '周三', '周四', '周五', '周六', '周日' ]
  95. },
  96. 'yAxis': {
  97. 'type': 'value'
  98. },
  99. 'series': [
  100. {
  101. 'name': '邮件营销',
  102. 'type': 'line',
  103. 'stack': '总量',
  104. 'data': [ 120, 132, 101, 134, 90, 230, 210 ]
  105. },
  106. {
  107. 'name': '联盟广告',
  108. 'type': 'line',
  109. 'stack': '总量',
  110. 'data': [ 220, 182, 191, 234, 290, 330, 310 ]
  111. },
  112. {
  113. 'name': '视频广告',
  114. 'type': 'line',
  115. 'stack': '总量',
  116. 'data': [ 150, 232, 201, 154, 190, 330, 410 ]
  117. },
  118. {
  119. 'name': '直接访问',
  120. 'type': 'line',
  121. 'stack': '总量',
  122. 'data': [ 320, 332, 301, 334, 390, 330, 320 ]
  123. },
  124. {
  125. 'name': '搜索引擎',
  126. 'type': 'line',
  127. 'stack': '总量',
  128. 'data': [ 820, 932, 901, 934, 1290, 1330, 1320 ]
  129. }
  130. ]
  131. }
  132. this.chartLine = echarts.init(document.getElementById('J_chartLineBox'))
  133. this.chartLine.setOption(option)
  134. window.addEventListener('resize', () => {
  135. this.chartLine.resize()
  136. })
  137. },
  138. // 柱状图
  139. initChartBar () {
  140. var option = {
  141. tooltip: {
  142. trigger: 'axis',
  143. axisPointer: {
  144. type: 'shadow'
  145. }
  146. },
  147. legend: {
  148. data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎', '百度', '谷歌', '必应', '其他']
  149. },
  150. grid: {
  151. left: '3%',
  152. right: '4%',
  153. bottom: '3%',
  154. containLabel: true
  155. },
  156. xAxis: [
  157. {
  158. type: 'category',
  159. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  160. }
  161. ],
  162. yAxis: [
  163. {
  164. type: 'value'
  165. }
  166. ],
  167. series: [
  168. {
  169. name: '直接访问',
  170. type: 'bar',
  171. data: [320, 332, 301, 334, 390, 330, 320]
  172. },
  173. {
  174. name: '邮件营销',
  175. type: 'bar',
  176. stack: '广告',
  177. data: [120, 132, 101, 134, 90, 230, 210]
  178. },
  179. {
  180. name: '联盟广告',
  181. type: 'bar',
  182. stack: '广告',
  183. data: [220, 182, 191, 234, 290, 330, 310]
  184. },
  185. {
  186. name: '视频广告',
  187. type: 'bar',
  188. stack: '广告',
  189. data: [150, 232, 201, 154, 190, 330, 410]
  190. },
  191. {
  192. name: '搜索引擎',
  193. type: 'bar',
  194. data: [862, 1018, 964, 1026, 1679, 1600, 1570],
  195. markLine: {
  196. lineStyle: {
  197. normal: {
  198. type: 'dashed'
  199. }
  200. },
  201. data: [
  202. [{ type: 'min' }, { type: 'max' }]
  203. ]
  204. }
  205. },
  206. {
  207. name: '百度',
  208. type: 'bar',
  209. barWidth: 5,
  210. stack: '搜索引擎',
  211. data: [620, 732, 701, 734, 1090, 1130, 1120]
  212. },
  213. {
  214. name: '谷歌',
  215. type: 'bar',
  216. stack: '搜索引擎',
  217. data: [120, 132, 101, 134, 290, 230, 220]
  218. },
  219. {
  220. name: '必应',
  221. type: 'bar',
  222. stack: '搜索引擎',
  223. data: [60, 72, 71, 74, 190, 130, 110]
  224. },
  225. {
  226. name: '其他',
  227. type: 'bar',
  228. stack: '搜索引擎',
  229. data: [62, 82, 91, 84, 109, 110, 120]
  230. }
  231. ]
  232. }
  233. this.chartBar = echarts.init(document.getElementById('J_chartBarBox'))
  234. this.chartBar.setOption(option)
  235. window.addEventListener('resize', () => {
  236. this.chartBar.resize()
  237. })
  238. },
  239. // 饼状图
  240. initChartPie () {
  241. var option = {
  242. backgroundColor: '#2c343c',
  243. title: {
  244. text: 'Customized Pie',
  245. left: 'center',
  246. top: 20,
  247. textStyle: {
  248. color: '#ccc'
  249. }
  250. },
  251. tooltip: {
  252. trigger: 'item',
  253. formatter: '{a} <br/>{b} : {c} ({d}%)'
  254. },
  255. visualMap: {
  256. show: false,
  257. min: 80,
  258. max: 600,
  259. inRange: {
  260. colorLightness: [0, 1]
  261. }
  262. },
  263. series: [
  264. {
  265. name: '访问来源',
  266. type: 'pie',
  267. radius: '55%',
  268. center: ['50%', '50%'],
  269. data: [
  270. { value: 335, name: '直接访问' },
  271. { value: 310, name: '邮件营销' },
  272. { value: 274, name: '联盟广告' },
  273. { value: 235, name: '视频广告' },
  274. { value: 400, name: '搜索引擎' }
  275. ].sort(function (a, b) { return a.value - b.value }),
  276. roseType: 'radius',
  277. label: {
  278. normal: {
  279. textStyle: {
  280. color: 'rgba(255, 255, 255, 0.3)'
  281. }
  282. }
  283. },
  284. labelLine: {
  285. normal: {
  286. lineStyle: {
  287. color: 'rgba(255, 255, 255, 0.3)'
  288. },
  289. smooth: 0.2,
  290. length: 10,
  291. length2: 20
  292. }
  293. },
  294. itemStyle: {
  295. normal: {
  296. color: '#c23531',
  297. shadowBlur: 200,
  298. shadowColor: 'rgba(0, 0, 0, 0.5)'
  299. }
  300. },
  301. animationType: 'scale',
  302. animationEasing: 'elasticOut',
  303. animationDelay: function (idx) {
  304. return Math.random() * 200
  305. }
  306. }
  307. ]
  308. }
  309. this.chartPie = echarts.init(document.getElementById('J_chartPieBox'))
  310. this.chartPie.setOption(option)
  311. window.addEventListener('resize', () => {
  312. this.chartPie.resize()
  313. })
  314. },
  315. // 散点图
  316. initChartScatter () {
  317. var option = {
  318. backgroundColor: new echarts.graphic.RadialGradient(0.3, 0.3, 0.8, [
  319. { offset: 0, color: '#f7f8fa' },
  320. { offset: 1, color: '#cdd0d5' }
  321. ]),
  322. title: {
  323. text: '1990 与 2015 年各国家人均寿命与 GDP'
  324. },
  325. legend: {
  326. right: 10,
  327. data: ['1990', '2015']
  328. },
  329. xAxis: {
  330. splitLine: {
  331. lineStyle: {
  332. type: 'dashed'
  333. }
  334. }
  335. },
  336. yAxis: {
  337. splitLine: {
  338. lineStyle: {
  339. type: 'dashed'
  340. }
  341. },
  342. scale: true
  343. },
  344. series: [
  345. {
  346. name: '1990',
  347. data: [
  348. [28604, 77, 17096869, 'Australia', 1990],
  349. [31163, 77.4, 27662440, 'Canada', 1990],
  350. [1516, 68, 1154605773, 'China', 1990],
  351. [13670, 74.7, 10582082, 'Cuba', 1990],
  352. [28599, 75, 4986705, 'Finland', 1990],
  353. [29476, 77.1, 56943299, 'France', 1990],
  354. [31476, 75.4, 78958237, 'Germany', 1990],
  355. [28666, 78.1, 254830, 'Iceland', 1990],
  356. [1777, 57.7, 870601776, 'India', 1990],
  357. [29550, 79.1, 122249285, 'Japan', 1990],
  358. [2076, 67.9, 20194354, 'North Korea', 1990],
  359. [12087, 72, 42972254, 'South Korea', 1990],
  360. [24021, 75.4, 3397534, 'New Zealand', 1990],
  361. [43296, 76.8, 4240375, 'Norway', 1990],
  362. [10088, 70.8, 38195258, 'Poland', 1990],
  363. [19349, 69.6, 147568552, 'Russia', 1990],
  364. [10670, 67.3, 53994605, 'Turkey', 1990],
  365. [26424, 75.7, 57110117, 'United Kingdom', 1990],
  366. [37062, 75.4, 252847810, 'United States', 1990]
  367. ],
  368. type: 'scatter',
  369. symbolSize: function (data) {
  370. return Math.sqrt(data[2]) / 5e2
  371. },
  372. label: {
  373. emphasis: {
  374. show: true,
  375. formatter: function (param) {
  376. return param.data[3]
  377. },
  378. position: 'top'
  379. }
  380. },
  381. itemStyle: {
  382. normal: {
  383. shadowBlur: 10,
  384. shadowColor: 'rgba(120, 36, 50, 0.5)',
  385. shadowOffsetY: 5,
  386. color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [
  387. { offset: 0, color: 'rgb(251, 118, 123)' },
  388. { offset: 1, color: 'rgb(204, 46, 72)' }
  389. ])
  390. }
  391. }
  392. },
  393. {
  394. name: '2015',
  395. data: [
  396. [44056, 81.8, 23968973, 'Australia', 2015],
  397. [43294, 81.7, 35939927, 'Canada', 2015],
  398. [13334, 76.9, 1376048943, 'China', 2015],
  399. [21291, 78.5, 11389562, 'Cuba', 2015],
  400. [38923, 80.8, 5503457, 'Finland', 2015],
  401. [37599, 81.9, 64395345, 'France', 2015],
  402. [44053, 81.1, 80688545, 'Germany', 2015],
  403. [42182, 82.8, 329425, 'Iceland', 2015],
  404. [5903, 66.8, 1311050527, 'India', 2015],
  405. [36162, 83.5, 126573481, 'Japan', 2015],
  406. [1390, 71.4, 25155317, 'North Korea', 2015],
  407. [34644, 80.7, 50293439, 'South Korea', 2015],
  408. [34186, 80.6, 4528526, 'New Zealand', 2015],
  409. [64304, 81.6, 5210967, 'Norway', 2015],
  410. [24787, 77.3, 38611794, 'Poland', 2015],
  411. [23038, 73.13, 143456918, 'Russia', 2015],
  412. [19360, 76.5, 78665830, 'Turkey', 2015],
  413. [38225, 81.4, 64715810, 'United Kingdom', 2015],
  414. [53354, 79.1, 321773631, 'United States', 2015]
  415. ],
  416. type: 'scatter',
  417. symbolSize: function (data) {
  418. return Math.sqrt(data[2]) / 5e2
  419. },
  420. label: {
  421. emphasis: {
  422. show: true,
  423. formatter: function (param) {
  424. return param.data[3]
  425. },
  426. position: 'top'
  427. }
  428. },
  429. itemStyle: {
  430. normal: {
  431. shadowBlur: 10,
  432. shadowColor: 'rgba(25, 100, 150, 0.5)',
  433. shadowOffsetY: 5,
  434. color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [
  435. { offset: 0, color: 'rgb(129, 227, 238)' },
  436. { offset: 1, color: 'rgb(25, 183, 207)' }
  437. ])
  438. }
  439. }
  440. }
  441. ]
  442. }
  443. this.chartPie = echarts.init(document.getElementById('J_chartScatterBox'))
  444. this.chartPie.setOption(option)
  445. window.addEventListener('resize', () => {
  446. this.chartPie.resize()
  447. })
  448. }
  449. }
  450. }
  451. </script>
  452. <style lang="scss">
  453. .mod-demo-echarts {
  454. > .el-alert {
  455. margin-bottom: 10px;
  456. }
  457. > .el-row {
  458. margin-top: -10px;
  459. margin-bottom: -10px;
  460. .el-col {
  461. padding-top: 10px;
  462. padding-bottom: 10px;
  463. }
  464. }
  465. .chart-box {
  466. min-height: 400px;
  467. }
  468. }
  469. </style>