当前位置:   article > 正文

基于vue3、echarts5.0、express、axios技术实现大数据可视化大屏项目_数字大屏vue3

数字大屏vue3

目录

一、首先搭建一个Vue3项目:

二、创建vue项目

三、运行项目

四、初始化项目

五、项目基本结构有:

中国地图数据可视化以及34个省级行政区地图显示,包括23个省、5个自治区、4个直辖市、2个特别行政区。(均可缩放、动态)。

世界汉化地图数据可视化(可缩放,动态)。

Echarts框架中的一些常用图表用于数据可视化。

用到的技术栈

六、技术栈分析:

1、flexible.js:  

2、全局设置Echarts和axios

3、后台接口创建express

七、项目中的部分代码

        1.中国地图代码

         2.图表一代码

         3.周销图代码

        4.库存统计代码 

        5.库存统计图代码 

         6.柱状图代码

         7.饼状图代码

         8.多条折线图代码

        9.散点图代码 

        10.K线图代码 

         11.自主定义主题代码

         12.漏斗图代码

        13.仪表盘代码 

         14.关系图代码

        15.数据区域缩放代码

         16.数据排序代码

         17.雷达图代码

        18.树形图代码 

        19.世界地图代码 

        20.中国城市地图代码 

        21.中国省份地图(34个)

八、部分代码解析 

        i.引入组件以及插槽的作用

        ii. 数据中提取特定的信息

        iii.使用ECharts图表库中的echarts.on方法来监听点击事件

九、容易忘记点(复习点)

十、页面截屏功能分析

十一:源码地址


一、首先搭建一个Vue3项目

电脑上安装node.js

网址:https://nodejs.org/zh-cn/

全局安装vue脚手架

网址:安装 | Vue CLI (vuejs.org)

npm i @vue/cli -g

查看node版本:npm -v

查看脚手架版本: npm -V

二、创建vue项目

Vue create 项目名称

把cmd的路径切换到指定路径下 vue create 项目名

        i.选择项目配置模板,选择第三项自主选择项目所需的配置

         ii.选择项目配置选项 勾选所需要的模块

         iii.选择想要开始项目的Vue.js版本 选择 3.x

         iv.是否用history模式来创建路由 直接回车默认项目

         v.选择CSS 预处理类型 选择Sass/Scss

         vi.项目的配置文件 (1.独立文件 2.package.json中)

         vii.是否保存配置当做后续项目的可选配置,选择不保存(enter回车确认开始创建)

三、运行项目

        i.把cmd的路径切换到项目名下

        ii.npm run serve 启动项目

四、初始化项目

        i.删除src文件夹下的cpmponents文件夹下的Helloword.vue文件。

        ii.删除vuews下的两个.vue文件。

        iii.在views中新建页面文件 homePage.vue文件。

        iv.修改router下的index.js配置路由文件。

        v.修改根组件默认显示内容与初始化项目样式

五、项目基本结构有:

  1. 中国地图数据可视化以及34个省级行政区地图显示,包括23个省、5个自治区、4个直辖市、2个特别行政区。(均可缩放、动态)。
  2. 世界汉化地图数据可视化(可缩放,动态)。
  3. Echarts框架中的一些常用图表用于数据可视化。
  4. 用到的技术栈

                i. vue3.0+vue-router4.0+axios

                ii. flex布局

                iii.SCSS

                iv. rem屏幕适配

                v. echarts5.0

                vi.Element Plus/icons-vue

六、技术栈分析:

1、flexible.js:  

        i.npm i -S lib-flexible 进行下载

        ii.在main.js中进行配置:

        iii.修改flexible配置:

                 默认情况下只会在540px分辨率一下生效所以需要根据我们的项目分辨率进行调整。

     在node_module/lib-flexible/flexible.js中修改代码如下:

        重启项目打开浏览器调试器,在浏览器大小改变的时候在html根节点上会自动设置一个font-size。

        配置cssrem插件:在vscode扩展中搜索cssrem插件最新名字叫px to rem & rpx 安装到vscode中点击右下角设置修改Root Font Size(基准font-size) 配置项为80即可:

2、全局设置Echarts和axios

        i.下载 npm install --save echarts

        ii.下载 npm install --save axios

      iii.Vue2.0中通过在main.js中引用echarts和axios,但在vue3.0中就不一样了,vue3中使用provide/inject依赖注入,将替代vue2中在原型链上挂载一些属性。

3、后台接口创建express

        i.下载 npm install express

        初始化:npm i

        启动: node app.js

        ii.在server文件夹下创建public文件夹用来容纳数据,引用并且把数据返回给前台。

        iii.创建一个文件夹 server 在其中创建app.js与router文件夹容来容纳代码。

        iv.在router下创建文件分别容纳对应的接口

        v.在app.js下引用使用刚才创建的内容

七、项目中的部分代码

        1.中国地图代码
  1. <template>
  2. <div>
  3. <div id="china"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import axios from "axios";
  8. //在后代中引入inject
  9. import { inject, onMounted, reactive } from "vue";
  10. import { useRouter } from "vue-router";
  11. export default {
  12. setup() {
  13. let $echarts = inject("echarts");
  14. let chinaData = reactive({});
  15. // 设置数据请求方法 不要忘了return
  16. async function getState() {
  17. chinaData = await axios.get("/china/data");
  18. }
  19. let router = useRouter();
  20. onMounted(() => {
  21. getState().then(() => {
  22. let echarts = $echarts.init(document.getElementById("china"));
  23. $echarts.registerMap("chinaMap", chinaData.data.chinaData);
  24. echarts.setOption({
  25. geo: {
  26. map: "chinaMap",
  27. // roam: true,
  28. zoom: 1.2,
  29. // color: "#0099ff",
  30. label: {
  31. //地图上显示文字提示信息
  32. show: true,
  33. color: "#fff",
  34. // areaColor: "#0099ff",
  35. // backgroundColor: "#0099ff",
  36. fontSize: 10, //字体大小
  37. },
  38. // center: [108.956239, 34.268309],
  39. itemStyle: {
  40. areaColor: "#0099ff",
  41. },
  42. emphasis: {
  43. focus: "self",
  44. itemStyle: {
  45. areaColor: "#fff",
  46. borderColor: "#00ffff",
  47. shadowColor: "rgba(230,130,70,0.5)",
  48. shadowBlur: 30,
  49. },
  50. },
  51. },
  52. title: {
  53. text: "城市销量",
  54. left: "center",
  55. textStyle: {
  56. color: "#fff",
  57. fontSize: 20,
  58. textShadowBlur: 10,
  59. textShadowColor: "#33ffff",
  60. },
  61. },
  62. tooltip: {
  63. trigger: "item",
  64. },
  65. // visualMap: {
  66. // type: "continuous",
  67. // min: 100,
  68. // max: 5000,
  69. // calculable: true,
  70. // inRange: {
  71. // color: ["#50a3ba", "#eac736", "#d94e5d"],
  72. // },
  73. // textStyle: {
  74. // color: "#fff",
  75. // },
  76. // },
  77. series: [
  78. {
  79. type: "effectScatter",
  80. symbolSize: 30,
  81. coordinateSystem: "geo",
  82. data: [
  83. { name: "呼和浩特", value: [111.652017, 40.861428] },
  84. // { name: "上海", value: [121.48, 31.22, 8675] },
  85. // { name: "深圳", value: [114.07, 22.62, 2461] },
  86. // { name: "广州", value: [113.23, 23.16, 187] },
  87. ],
  88. rippleEffect: {
  89. //涟漪特效相关配置。
  90. number: 2, //波纹的数量。
  91. scale: 4, //动画中波纹的最大缩放比例
  92. },
  93. itemStyle: {
  94. color: "#f99",
  95. },
  96. }, // 也可以绘制点效果
  97. {
  98. symbolSize: 10,
  99. type: "effectScatter",
  100. coordinateSystem: "geo", series坐标系类型
  101. data: [
  102. { name: "桂林市", value: [110.193673, 25.244837] },
  103. { name: "成都市", value: [104.077344, 30.582476] },
  104. { name: "拉萨市", value: [91.180183, 29.660491] },
  105. { name: "丽江市", value: [100.237061, 26.861173] },
  106. { name: "深圳市", value: [114.001167, 22.681125] },
  107. { name: "湛江市", value: [110.363254, 21.276185] },
  108. { name: "上海", value: [121.481115, 31.238893] },
  109. ],
  110. rippleEffect: {
  111. number: 2,
  112. scale: 5,
  113. },
  114. itemStyle: {
  115. color: "#f00",
  116. },
  117. },
  118. ],
  119. });
  120. echarts.on("click", function (params) {
  121. if (params.componentType === "geo") {
  122. if (params.componentIndex === 0) {
  123. var clickedProvince = params.name;
  124. console.log(clickedProvince);
  125. if (provinceRoutes.hasOwnProperty(clickedProvince)) {
  126. router.push({ name: provinceRoutes[clickedProvince] });
  127. }
  128. }
  129. }
  130. });
  131. const provinceRoutes = {
  132. 广东: "guangdong",
  133. 广西: "guangxi",
  134. 安徽: "anhui",
  135. 新疆: "xinjiang",
  136. 西藏: "xizang",
  137. 内蒙古: "neimenggu",
  138. 宁夏: "ningxia",
  139. 青海: "qinghai",
  140. 甘肃: "gansu",
  141. 四川: "sichuan",
  142. 重庆: "chongqing",
  143. 云南: "yunnan",
  144. 贵州: "guizhou",
  145. 陕西: "shanxi",
  146. 山西: "shanx",
  147. 湖南: "hunan",
  148. 湖北: "hubei",
  149. 河南: "henan",
  150. 河北: "hebei",
  151. 山东: "shandong",
  152. 北京: "beijing",
  153. 天津: "tianjin",
  154. 江西: "jiangxi",
  155. 福建: "fujian",
  156. 台湾: "taiwan",
  157. 香港: "xianggang",
  158. 澳门: "aomen",
  159. 海南: "hainan",
  160. 浙江: "zhejiang",
  161. 上海: "shanghai",
  162. 江苏: "jiangsu",
  163. 辽宁: "liaoning",
  164. 吉林: "jilin",
  165. 黑龙江: "heilongjiang",
  166. };
  167. });
  168. });
  169. return {
  170. getState,
  171. chinaData,
  172. };
  173. },
  174. };
  175. </script>
  176. <style lang="scss">
  177. #china {
  178. height: 10rem;
  179. }
  180. </style>
         2.图表一代码
  1. <template>
  2. <div>
  3. <div class="chart" id="onechart">图表的容器</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("onechart"));
  13. echarts.setOption({
  14. title: {
  15. text: "图表1",
  16. left: "center",
  17. textStyle: {
  18. color: "#fff",
  19. fontSize: 20,
  20. textShadowBlur: 10,
  21. textShadowColor: "#33ffff",
  22. },
  23. },
  24. tooltip: {
  25. trigger: "axis",
  26. },
  27. grid: {
  28. left: "1%",
  29. right: "10%",
  30. top: "9%",
  31. bottom: "1%",
  32. containLabel: "true",
  33. },
  34. toolbox: {
  35. iconStyle: {
  36. // color: "#fff",
  37. borderColor: "#fff",
  38. },
  39. show: true,
  40. feature: {
  41. // dataZoom: {
  42. // yAxisIndex: "none",
  43. // },
  44. dataView: { readOnly: false },
  45. magicType: { type: ["line"] },
  46. restore: {},
  47. saveAsImage: {},
  48. },
  49. },
  50. xAxis: {
  51. type: "value",
  52. axisLine: {
  53. lineStyle: {
  54. color: "#fff",
  55. },
  56. },
  57. },
  58. yAxis: {
  59. type: "category",
  60. axisLine: {
  61. lineStyle: {
  62. color: "#fff",
  63. },
  64. },
  65. data: [
  66. "洗碗机",
  67. "空调",
  68. "烤箱",
  69. "微波炉",
  70. "电视机",
  71. "洗衣机",
  72. "冰箱",
  73. ],
  74. },
  75. series: {
  76. type: "bar",
  77. data: [1827, 342, 541, 1347, 2431, 876, 1578],
  78. itemStyle: {
  79. barBorderRadius: [0, 30, 30, 0],
  80. color: new $echarts.graphic.LinearGradient(0, 0, 1, 0, [
  81. {
  82. offset: 0,
  83. color: "#005eaa",
  84. },
  85. {
  86. offset: 0.5,
  87. color: "#339ca8",
  88. },
  89. {
  90. offset: 1,
  91. color: "#cda819",
  92. },
  93. ]),
  94. },
  95. },
  96. });
  97. });
  98. },
  99. };
  100. </script>
  101. <style lang="scss">
  102. #onechart {
  103. height: 5.125rem;
  104. }
  105. </style>
         3.周销图代码
  1. <template>
  2. <div>
  3. <div id="echarttwo"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("echarttwo"));
  13. echarts.setOption({
  14. color: ["#80FFA5", "#00DDFF", "#37A2FF", "#FF0087", "#FFBF00"],
  15. title: {
  16. text: "周销图",
  17. left: "center",
  18. textStyle: {
  19. color: "#fff",
  20. fontSize: 20,
  21. textShadowBlur: 10,
  22. textShadowColor: "#33ffff",
  23. },
  24. },
  25. tooltip: {
  26. trigger: "axis",
  27. axisPointer: {
  28. type: "cross",
  29. label: {
  30. backgroundColor: "#6a7985",
  31. },
  32. },
  33. },
  34. legend: {
  35. top: "9%",
  36. data: ["服装", "数码", "家电", "家居", "日化"],
  37. },
  38. toolbox: {
  39. iconStyle: {
  40. // color: "#fff",
  41. borderColor: "#fff",
  42. },
  43. show: true,
  44. feature: {
  45. // dataZoom: {
  46. // yAxisIndex: "none",
  47. // },
  48. dataView: { readOnly: false },
  49. magicType: { type: ["bar"] },
  50. restore: {},
  51. saveAsImage: {},
  52. },
  53. },
  54. grid: {
  55. top: "25%",
  56. left: "1%",
  57. right: "4%",
  58. bottom: "1%",
  59. containLabel: true,
  60. },
  61. xAxis: [
  62. {
  63. type: "category",
  64. boundaryGap: false,
  65. data: [
  66. "星期一",
  67. "星期二",
  68. "星期三",
  69. "星期四",
  70. "星期五",
  71. "星期六",
  72. "星期天",
  73. ],
  74. axisLine: {
  75. lineStyle: {
  76. color: "#fff",
  77. },
  78. },
  79. },
  80. ],
  81. yAxis: [
  82. {
  83. type: "value",
  84. axisLine: {
  85. lineStyle: {
  86. color: "#fff",
  87. },
  88. },
  89. },
  90. ],
  91. series: [
  92. {
  93. name: "服装",
  94. type: "line",
  95. stack: "Total",
  96. smooth: true,
  97. lineStyle: {
  98. width: 0,
  99. },
  100. showSymbol: false,
  101. areaStyle: {
  102. opacity: 0.8,
  103. color: new $echarts.graphic.LinearGradient(0, 0, 0, 1, [
  104. {
  105. offset: 0,
  106. color: "rgb(128, 255, 165)",
  107. },
  108. {
  109. offset: 1,
  110. color: "rgb(1, 191, 236)",
  111. },
  112. ]),
  113. },
  114. emphasis: {
  115. focus: "series",
  116. },
  117. data: [140, 232, 101, 264, 90, 340, 250],
  118. },
  119. {
  120. name: "数码",
  121. type: "line",
  122. stack: "Total",
  123. smooth: true,
  124. lineStyle: {
  125. width: 0,
  126. },
  127. showSymbol: false,
  128. areaStyle: {
  129. opacity: 0.8,
  130. color: new $echarts.graphic.LinearGradient(0, 0, 0, 1, [
  131. {
  132. offset: 0,
  133. color: "rgb(0, 221, 255)",
  134. },
  135. {
  136. offset: 1,
  137. color: "rgb(77, 119, 255)",
  138. },
  139. ]),
  140. },
  141. emphasis: {
  142. focus: "series",
  143. },
  144. data: [120, 282, 111, 234, 220, 340, 310],
  145. },
  146. {
  147. name: "家电",
  148. type: "line",
  149. stack: "Total",
  150. smooth: true,
  151. lineStyle: {
  152. width: 0,
  153. },
  154. showSymbol: false,
  155. areaStyle: {
  156. opacity: 0.8,
  157. color: new $echarts.graphic.LinearGradient(0, 0, 0, 1, [
  158. {
  159. offset: 0,
  160. color: "rgb(55, 162, 255)",
  161. },
  162. {
  163. offset: 1,
  164. color: "rgb(116, 21, 219)",
  165. },
  166. ]),
  167. },
  168. emphasis: {
  169. focus: "series",
  170. },
  171. data: [320, 132, 201, 334, 190, 130, 220],
  172. },
  173. {
  174. name: "家居",
  175. type: "line",
  176. stack: "Total",
  177. smooth: true,
  178. lineStyle: {
  179. width: 0,
  180. },
  181. showSymbol: false,
  182. areaStyle: {
  183. opacity: 0.8,
  184. color: new $echarts.graphic.LinearGradient(0, 0, 0, 1, [
  185. {
  186. offset: 0,
  187. color: "rgb(255, 0, 135)",
  188. },
  189. {
  190. offset: 1,
  191. color: "rgb(135, 0, 157)",
  192. },
  193. ]),
  194. },
  195. emphasis: {
  196. focus: "series",
  197. },
  198. data: [220, 402, 231, 134, 190, 230, 120],
  199. },
  200. {
  201. name: "日化",
  202. type: "line",
  203. stack: "Total",
  204. smooth: true,
  205. lineStyle: {
  206. width: 0,
  207. },
  208. showSymbol: false,
  209. label: {
  210. show: true,
  211. position: "top",
  212. },
  213. areaStyle: {
  214. opacity: 0.8,
  215. color: new $echarts.graphic.LinearGradient(0, 0, 0, 1, [
  216. {
  217. offset: 0,
  218. color: "rgb(255, 191, 0)",
  219. },
  220. {
  221. offset: 1,
  222. color: "rgb(224, 62, 76)",
  223. },
  224. ]),
  225. },
  226. emphasis: {
  227. focus: "series",
  228. },
  229. data: [220, 302, 181, 234, 210, 290, 150],
  230. },
  231. ],
  232. });
  233. });
  234. },
  235. };
  236. </script>
  237. <style>
  238. #echarttwo {
  239. height: 5.125rem;
  240. }
  241. </style>
        4.库存统计代码 
  1. <template>
  2. <div>
  3. <div id="echartthree"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("echartthree"));
  13. echarts.setOption({
  14. title: {
  15. text: "库存统计",
  16. left: "center",
  17. textStyle: {
  18. color: "#fff",
  19. fontSize: 20,
  20. textShadowBlur: 10,
  21. textShadowColor: "#33ffff",
  22. },
  23. },
  24. toolbox: {
  25. iconStyle: {
  26. // color: "#fff",
  27. borderColor: "#fff",
  28. },
  29. show: true,
  30. feature: {
  31. // dataZoom: {
  32. // yAxisIndex: "none",
  33. // },
  34. dataView: { readOnly: false },
  35. restore: {},
  36. saveAsImage: {},
  37. },
  38. },
  39. legend: {
  40. orient: "horizontal",
  41. // width: ".1rem",
  42. // itemGap: "0.01rem",
  43. top: "bottom",
  44. },
  45. tooltip: {
  46. show: true,
  47. },
  48. series: {
  49. type: "pie",
  50. data: [
  51. { value: 567, name: "服饰" },
  52. { value: 123, name: "数码" },
  53. { value: 324, name: "家电" },
  54. { value: 89, name: "家居" },
  55. { value: 453, name: "日化" },
  56. { value: 767, name: "熟食" },
  57. ],
  58. roseType: "area",
  59. center: ["50%", "45%"],
  60. radius: [10, 100],
  61. itemStyle: {
  62. borderRadius: 10,
  63. },
  64. },
  65. });
  66. });
  67. },
  68. };
  69. </script>
  70. <style>
  71. #echartthree {
  72. height: 5.125rem;
  73. }
  74. </style>
        5.库存统计图代码 
  1. <template>
  2. <div>
  3. <div id="echartfour"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("echartfour"));
  13. echarts.setOption({
  14. title: {
  15. text: "库存统计图",
  16. left: "center",
  17. textStyle: {
  18. color: "#fff",
  19. fontSize: 20,
  20. textShadowBlur: 10,
  21. textShadowColor: "#33ffff",
  22. },
  23. },
  24. toolbox: {
  25. iconStyle: {
  26. // color: "#fff",
  27. borderColor: "#fff",
  28. },
  29. show: true,
  30. feature: {
  31. // dataZoom: {
  32. // yAxisIndex: "none",
  33. // },
  34. dataView: { readOnly: false },
  35. magicType: { type: ["line"] },
  36. restore: {},
  37. saveAsImage: {},
  38. },
  39. },
  40. tooltip: {
  41. type: "axis",
  42. },
  43. grid: {
  44. left: "1%",
  45. bottom: "1%",
  46. right: "3%",
  47. containLabel: "true",
  48. },
  49. legend: {
  50. top: "10%",
  51. },
  52. xAxis: {
  53. type: "category",
  54. data: [
  55. "星期一",
  56. "星期二",
  57. "星期三",
  58. "星期四",
  59. "星期五",
  60. "星期六",
  61. "星期天",
  62. ],
  63. axisLine: {
  64. lineStyle: {
  65. color: "#fff",
  66. },
  67. },
  68. },
  69. yAxis: {
  70. type: "value",
  71. axisLine: {
  72. lineStyle: {
  73. color: "#fff",
  74. },
  75. },
  76. },
  77. series: [
  78. {
  79. name: "服装",
  80. type: "bar",
  81. data: [320, 502, 401, 334, 390, 430, 720],
  82. stack: "total",
  83. label: {
  84. show: true,
  85. },
  86. emphasis: {
  87. focus: true,
  88. },
  89. },
  90. {
  91. name: "数码",
  92. type: "bar",
  93. data: [234, 564, 443, 234, 754, 430, 321],
  94. stack: "total",
  95. label: {
  96. show: true,
  97. },
  98. emphasis: {
  99. focus: true,
  100. },
  101. },
  102. {
  103. name: "家电",
  104. type: "bar",
  105. data: [220, 321, 335, 534, 390, 330, 310],
  106. stack: "total",
  107. label: {
  108. show: true,
  109. },
  110. emphasis: {
  111. focus: true,
  112. },
  113. },
  114. {
  115. name: "家居",
  116. type: "bar",
  117. data: [269, 212, 491, 368, 341, 330, 410],
  118. stack: "total",
  119. label: {
  120. show: true,
  121. },
  122. emphasis: {
  123. focus: true,
  124. },
  125. },
  126. {
  127. name: "日化",
  128. type: "bar",
  129. data: [820, 832, 901, 934, 1290, 1330, 1320],
  130. stack: "total",
  131. label: {
  132. show: true,
  133. },
  134. emphasis: {
  135. focus: true,
  136. },
  137. },
  138. ],
  139. });
  140. });
  141. },
  142. };
  143. </script>
  144. <style lang="scss">
  145. #echartfour {
  146. height: 5.125rem;
  147. }
  148. </style>
         6.柱状图代码
  1. <template>
  2. <div>
  3. <div id="one">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("one"));
  13. let xData = ["美食", "数码", "日化", "蔬菜", "熟食"];
  14. let yData = [88, 120, 70, 210, 50];
  15. echarts.setOption({
  16. title: {
  17. text: "柱形图",
  18. left: "center",
  19. textStyle: {
  20. color: "#fff",
  21. textShadowBlur: 10,
  22. textShadowColor: "#33ffff",
  23. },
  24. },
  25. toolbox: {
  26. iconStyle: {
  27. borderColor: "#fff",
  28. },
  29. show: true,
  30. feature: {
  31. dataView: { readOnly: false },
  32. magicType: { type: ["line"] },
  33. restore: {},
  34. saveAsImage: {},
  35. },
  36. },
  37. grid: {
  38. // show: true,
  39. left: "1%",
  40. right: "12%",
  41. bottom: "1%",
  42. containLabel: true,
  43. },
  44. tooltip: {
  45. trigger: "axis",
  46. },
  47. // legend: {
  48. // top: "6%",
  49. // },
  50. xAxis: {
  51. type: "category",
  52. data: xData,
  53. axisLine: {
  54. lineStyle: {
  55. color: "#fff",
  56. },
  57. },
  58. },
  59. yAxis: {
  60. value: "value",
  61. axisLine: {
  62. lineStyle: {
  63. color: "#fff",
  64. },
  65. },
  66. },
  67. series: [
  68. {
  69. name: "销量",
  70. type: "bar",
  71. data: yData,
  72. barWidth: 25,
  73. itemStyle: {
  74. // normal: {
  75. // barBorderRadius: [20, 20, 0, 0],
  76. // color: function (parmas) {
  77. // let colorList = [
  78. // "#ff2355",
  79. // "#cc22cc",
  80. // "#0000ff",
  81. // "#00ff00",
  82. // "#22aa00",
  83. // ];
  84. // return colorList[parmas.dataIndex];
  85. // },
  86. // },
  87. barBorderRadius: [10, 10, 0, 0],
  88. color: new $echarts.graphic.LinearGradient(0, 1, 0, 0, [
  89. {
  90. offset: 0,
  91. color: "#ff09ff",
  92. },
  93. {
  94. offset: 0.5,
  95. color: "#00ff22",
  96. },
  97. {
  98. offset: 1,
  99. color: "#44ffbb",
  100. },
  101. ]),
  102. },
  103. markPoint: {
  104. data: [
  105. {
  106. type: "max",
  107. name: "最大值",
  108. label: { color: "#000" },
  109. },
  110. {
  111. type: "min",
  112. name: "最小值",
  113. label: { color: "#000" },
  114. },
  115. ],
  116. },
  117. markLine: {
  118. data: [
  119. {
  120. type: "average",
  121. name: "平均值",
  122. },
  123. ],
  124. },
  125. },
  126. ],
  127. });
  128. });
  129. },
  130. };
  131. </script>
  132. <style>
  133. #one {
  134. height: 5.125rem;
  135. }
  136. </style>
         7.饼状图代码
  1. <template>
  2. <div>
  3. <div id="two"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("two"));
  13. let data = [
  14. {
  15. value: 69,
  16. name: "美食",
  17. },
  18. {
  19. value: 150,
  20. name: "日化",
  21. },
  22. {
  23. value: 100,
  24. name: "数码",
  25. },
  26. {
  27. value: 120,
  28. name: "家电",
  29. },
  30. ];
  31. echarts.setOption({
  32. title: {
  33. text: "饼状图",
  34. left: "center",
  35. textStyle: {
  36. color: "#fff",
  37. textShadowBlur: 10,
  38. textShadowColor: "#33ffff",
  39. },
  40. },
  41. toolbox: {
  42. iconStyle: {
  43. borderColor: "#fff",
  44. },
  45. show: true,
  46. feature: {
  47. dataView: { readOnly: false },
  48. saveAsImage: {},
  49. },
  50. },
  51. // grid: {
  52. // },
  53. tooltip: {
  54. trigger: "item",
  55. },
  56. legend: {
  57. left: "left",
  58. orient: "vertical",
  59. },
  60. // xAxis: {
  61. // type: "value",
  62. // data: [],
  63. // },
  64. // yAxis: {
  65. // value: "category",
  66. // data: [],
  67. // },
  68. series: [
  69. {
  70. name: "销量统计",
  71. type: "pie",
  72. data,
  73. radius: ["40%", "80%"],
  74. roseType: true,
  75. label: {
  76. position: "inside",
  77. },
  78. itemStyle: {
  79. color: function (parmas) {
  80. let colorList = ["#ff0000", "#00ff00", "#0000ff", "#00ffaa"];
  81. return colorList[parmas.dataIndex];
  82. },
  83. // normal: {
  84. // color: new $echarts.graphic.LinearGradient(0, 0, 1, 0, [
  85. // // {
  86. // // offset: 0,
  87. // // color: "#ff0000",
  88. // // },
  89. // {
  90. // offset: 0.4,
  91. // color: "#00ff00",
  92. // },
  93. // // {
  94. // // offset: 0.7,
  95. // // color: "#0000ff",
  96. // // },
  97. // {
  98. // offset: 1,
  99. // color: "#ff08ff",
  100. // },
  101. // ]),
  102. // },
  103. },
  104. },
  105. ],
  106. });
  107. });
  108. },
  109. };
  110. </script>
  111. <style>
  112. #two {
  113. height: 5.125rem;
  114. }
  115. </style>
         8.多条折线图代码
  1. <template>
  2. <div>
  3. <div id="three">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("three"));
  13. let xData = [
  14. "星期一",
  15. "星期二",
  16. "星期三",
  17. "星期四",
  18. "星期五",
  19. "星期六",
  20. "星期天",
  21. ];
  22. let yDataA = [55, 66, 77, 88, 99, 58, 100];
  23. let yDataB = [15, 20, 12, 15, 30, 35, 40];
  24. let yDataC = [23, 56, 46, 26, 50, 20, 50];
  25. let yDataD = [46, 23, 45, 65, 34, 89, 53];
  26. echarts.setOption({
  27. title: {
  28. text: "多条折线图",
  29. left: "center",
  30. textStyle: {
  31. color: "#fff",
  32. textShadowBlur: 10,
  33. textShadowColor: "#33ffff",
  34. },
  35. },
  36. grid: {
  37. show: true,
  38. left: "1%",
  39. bottom: "1%",
  40. right: "6%",
  41. containLabel: true,
  42. },
  43. toolbox: {
  44. iconStyle: {
  45. borderColor: "#fff",
  46. },
  47. feature: {
  48. dataView: { readOnly: false },
  49. magicType: { type: ["bar", "line"] },
  50. restore: {},
  51. saveAsImage: {},
  52. },
  53. },
  54. tooltip: {
  55. trigger: "axis",
  56. },
  57. legend: {
  58. top: "10%",
  59. },
  60. xAxis: {
  61. type: "category",
  62. data: xData,
  63. axisLine: {
  64. lineStyle: {
  65. color: "#fff",
  66. },
  67. },
  68. },
  69. yAxis: {
  70. value: "value",
  71. // boundaryGap: "false",
  72. // show: "true",
  73. axisLine: {
  74. lineStyle: {
  75. color: "#fff",
  76. },
  77. },
  78. },
  79. series: [
  80. {
  81. name: "美食",
  82. type: "line",
  83. data: yDataA,
  84. smooth: true,
  85. areaStyle: {},
  86. showSymbol: false,
  87. lineStyle: {
  88. width: 0,
  89. },
  90. stack: "num",
  91. emphasis: {
  92. focus: "series",
  93. },
  94. },
  95. {
  96. name: "家电",
  97. type: "line",
  98. data: yDataB,
  99. smooth: true,
  100. areaStyle: {},
  101. showSymbol: false,
  102. lineStyle: {
  103. width: 0,
  104. },
  105. stack: "num",
  106. emphasis: {
  107. focus: "series",
  108. },
  109. },
  110. {
  111. name: "日化",
  112. type: "line",
  113. data: yDataC,
  114. smooth: true,
  115. areaStyle: {},
  116. showSymbol: false,
  117. lineStyle: {
  118. width: 0,
  119. },
  120. stack: "num",
  121. emphasis: {
  122. focus: "series",
  123. },
  124. },
  125. {
  126. name: "家居",
  127. type: "line",
  128. data: yDataD,
  129. smooth: true,
  130. areaStyle: {},
  131. showSymbol: false,
  132. lineStyle: {
  133. width: 0,
  134. },
  135. stack: "num",
  136. emphasis: {
  137. focus: "series",
  138. },
  139. },
  140. ],
  141. });
  142. });
  143. },
  144. };
  145. </script>
  146. <style>
  147. #three {
  148. height: 5.125rem;
  149. }
  150. </style>
        9.散点图代码 
  1. <template>
  2. <div>
  3. <div id="four">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. // echarts中默认主题有两个:light、dark
  13. // echarts.init(选取容器dom,'主题')
  14. let echarts = $echarts.init(document.getElementById("four"), "dark");
  15. echarts.setOption({
  16. title: {
  17. text: "散点图",
  18. left: "center",
  19. textStyle: {
  20. color: "#fff",
  21. textShadowBlur: 10,
  22. textShadowColor: "#33ffff",
  23. },
  24. },
  25. toolbox: {
  26. iconStyle: {
  27. borderColor: "#fff",
  28. },
  29. feature: {
  30. dataView: { readOnly: false },
  31. restore: {},
  32. saveAsImage: {},
  33. },
  34. },
  35. grid: {
  36. left: "1%",
  37. bottom: "1%",
  38. right: "6%",
  39. containLabel: true,
  40. },
  41. tooltip: {
  42. trigger: "axis",
  43. },
  44. legend: {},
  45. xAxis: {
  46. axisLine: {
  47. lineStyle: {
  48. color: "#fff",
  49. },
  50. },
  51. },
  52. yAxis: {
  53. axisLine: {
  54. lineStyle: {
  55. color: "#fff",
  56. },
  57. },
  58. },
  59. series: [
  60. {
  61. type: "scatter",
  62. data: [
  63. [2.0, 4.04],
  64. [1.07, 2.33],
  65. [3.0, 4.04],
  66. [8.07, 1.33],
  67. [9.0, 7.04],
  68. [2.0, 4.04],
  69. [1.07, 1.33],
  70. [1.0, 1.04],
  71. [2.07, 2.33],
  72. [3.0, 3.04],
  73. [1.27, 0.33],
  74. [3.0, 9.65],
  75. [9.05, 8.23],
  76. [18.0, 9.76],
  77. [15.0, 7.56],
  78. [23.4, 5.31],
  79. [10.1, 7.47],
  80. [16.0, 8.26],
  81. [12.7, 3.53],
  82. [9.35, 7.2],
  83. [7.4, 8.2],
  84. [3.07, 4.82],
  85. [18.2, 6.83],
  86. [2.02, 4.47],
  87. [1.05, 3.33],
  88. [4.05, 4.96],
  89. [6.03, 7.24],
  90. [17.0, 6.55],
  91. [12.0, 8.84],
  92. [8.18, 5.82],
  93. [6.32, 5.68],
  94. ],
  95. SymbolSize: 20,
  96. itemStyle: {
  97. color: new $echarts.graphic.LinearGradient(0, 0, 1, 0, [
  98. {
  99. offset: 0,
  100. color: "#00ff00",
  101. },
  102. {
  103. offset: 1,
  104. color: "#ff0000",
  105. },
  106. ]),
  107. },
  108. emphasis: {
  109. itemStyle: {
  110. borderColor: "rgba(103,205,45,0.3)",
  111. borderWidth: 30,
  112. },
  113. },
  114. },
  115. ],
  116. });
  117. });
  118. },
  119. };
  120. </script>
  121. <style>
  122. #four {
  123. height: 5.12rem;
  124. }
  125. </style>
        10.K线图代码 
  1. <template>
  2. <div>
  3. <div id="five">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { computed, inject, onMounted, reactive } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. const data = reactive({
  12. data: [
  13. [20, 34, 10, 38],
  14. [40, 35, 30, 50],
  15. [31, 38, 33, 44],
  16. [38, 15, 5, 42],
  17. ],
  18. });
  19. const newarr = computed(() => {
  20. return data.data.map((v) => v[0]); // 获取data的第一列数据
  21. });
  22. onMounted(() => {
  23. // console.log(this.data);
  24. let echarts = $echarts.init(document.getElementById("five"));
  25. echarts.setOption({
  26. title: {
  27. text: "K线图",
  28. left: "center",
  29. textStyle: {
  30. color: "#fff",
  31. textShadowBlur: 10,
  32. textShadowColor: "#33ffff",
  33. },
  34. },
  35. toolbox: {
  36. iconStyle: {
  37. borderColor: "#fff",
  38. },
  39. feature: {
  40. dataView: { readOnly: false },
  41. restore: {},
  42. saveAsImage: {},
  43. },
  44. },
  45. grid: {
  46. left: "1%",
  47. bottom: "1%",
  48. containLabel: true,
  49. },
  50. tooltip: {
  51. trigger: "axis",
  52. axisPointer: {
  53. type: "cross",
  54. },
  55. },
  56. legend: {},
  57. xAxis: {
  58. type: "category",
  59. axisLine: {
  60. lineStyle: {
  61. color: "#fff",
  62. },
  63. },
  64. data: ["蔬菜", "水果", "熟食", "便捷食品"],
  65. },
  66. yAxis: {
  67. value: "value",
  68. axisLine: {
  69. lineStyle: {
  70. color: "#fff",
  71. },
  72. },
  73. },
  74. series: [
  75. {
  76. type: "candlestick",
  77. data: data.data,
  78. itemStyle: {
  79. color: "#00ff00",
  80. color0: "pink",
  81. borderColor: "null",
  82. borderColor0: "null",
  83. },
  84. markPoint: {
  85. data: [
  86. {
  87. name: "最大值",
  88. type: "max",
  89. valueDim: "highest",
  90. },
  91. {
  92. name: "最小值",
  93. type: "min",
  94. valueDim: "lowest",
  95. },
  96. ],
  97. },
  98. },
  99. {
  100. // name: "MA20",
  101. type: "line",
  102. data: newarr.value, // 访问计算属性的值需要使用 ".value"
  103. smooth: true,
  104. lineStyle: {
  105. opacity: 0.5,
  106. },
  107. },
  108. ],
  109. });
  110. });
  111. return {
  112. data,
  113. newarr,
  114. };
  115. },
  116. };
  117. </script>
  118. <style>
  119. #five {
  120. height: 5.125rem;
  121. }
  122. </style>
         11.自主定义主题代码
  1. <template>
  2. <div>
  3. <div id="sixteen">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. import { roma } from "../../assets/roma.js";
  9. export default {
  10. setup() {
  11. let $echarts = inject("echarts");
  12. onMounted(() => {
  13. // echarts中默认主题有两个:light、dark
  14. // echarts.init(选取容器dom,'主题')
  15. // 1.在主题编辑器中编辑主题
  16. // 主题编辑器地址:https://echarts.apache.org/zh/theme-builder.html
  17. // 2.下载对应主题json格式
  18. // 3.创建js文件把刚才下载的文件写入并且暴露
  19. // let roma=你的主题json
  20. // export default roma
  21. // 4.引用主题文件
  22. // import roma from "../assets/roma"
  23. let echarts = $echarts.init(
  24. document.getElementById("sixteen"),
  25. // "dark",
  26. roma
  27. );
  28. echarts.setOption({
  29. title: {
  30. text: "自定义主题",
  31. left: "center",
  32. textStyle: {
  33. color: "#fff",
  34. textShadowBlur: 10,
  35. textShadowColor: "#33ffff",
  36. },
  37. },
  38. grid: {
  39. // top: "50%",
  40. },
  41. tooltip: {
  42. trigger: "item",
  43. },
  44. legend: {
  45. top: 25,
  46. textStyle: {
  47. color: "#ffffff", // 设置图例字体颜色为白色
  48. fontSize: 14,
  49. },
  50. },
  51. // xAxis: {},
  52. // yAxis: {},
  53. series: [
  54. {
  55. type: "pie",
  56. emphasis: {
  57. //选中高亮的标签和图形样式。
  58. label: {
  59. fontSize: 20,
  60. },
  61. },
  62. data: [
  63. { value: 88, name: "美食" },
  64. { value: 75, name: "日化" },
  65. { value: 34, name: "数码" },
  66. { value: 67, name: "蔬菜" },
  67. { value: 32, name: "熟食" },
  68. ],
  69. center: ["50%", "55%"],
  70. // radius: "60%",
  71. label: {
  72. position: "inside",
  73. show: true,
  74. color: "red",
  75. fontSize: 14,
  76. },
  77. },
  78. ],
  79. });
  80. });
  81. },
  82. };
  83. </script>
  84. <style>
  85. #sixteen {
  86. height: 5.125rem;
  87. }
  88. </style>
         12.漏斗图代码
  1. <template>
  2. <div>
  3. <div id="seven">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("seven"));
  13. echarts.setOption({
  14. title: {
  15. text: "漏斗图",
  16. left: "center",
  17. textStyle: {
  18. color: "#fff",
  19. textShadowBlur: 10,
  20. textShadowColor: "#33ffff",
  21. },
  22. },
  23. toolbox: {
  24. iconStyle: {
  25. borderColor: "#fff",
  26. },
  27. feature: {
  28. dataView: { readOnly: false },
  29. restore: {},
  30. saveAsImage: {},
  31. },
  32. },
  33. grid: {},
  34. tooltip: {
  35. trigger: "item",
  36. formatter: "{a} <br/>{b} : {c}%",
  37. },
  38. legend: {
  39. top: 30,
  40. },
  41. series: [
  42. {
  43. type: "funnel",
  44. emphasis: {
  45. //选中高亮的标签和图形样式。
  46. label: {
  47. fontSize: 20,
  48. },
  49. },
  50. data: [
  51. { value: 60, name: "美食" },
  52. { value: 40, name: "日化" },
  53. { value: 20, name: "数码" },
  54. { value: 80, name: "家电" },
  55. { value: 100, name: "蔬菜" },
  56. ],
  57. sort: "descending",
  58. top: 70,
  59. left: 20,
  60. right: 10,
  61. bottom: 10,
  62. label: {
  63. show: true,
  64. position: "inside",
  65. },
  66. // gap: 1,
  67. itemStyle: {
  68. borderColor: "red",
  69. // color: "red",
  70. },
  71. },
  72. ],
  73. });
  74. });
  75. },
  76. };
  77. </script>
  78. <style>
  79. #seven {
  80. height: 5.125rem;
  81. }
  82. </style>
        13.仪表盘代码 
  1. <template>
  2. <div>
  3. <div id="eleven">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("eleven"), "dark");
  13. echarts.setOption({
  14. title: {
  15. text: "仪表盘",
  16. left: "center",
  17. textStyle: {
  18. color: "#fff",
  19. textShadowBlur: 10,
  20. textShadowColor: "#33ffff",
  21. },
  22. },
  23. grid: {
  24. bottom: "0%",
  25. },
  26. tooltip: {
  27. trigger: "axis",
  28. },
  29. legend: {},
  30. series: [
  31. {
  32. type: "gauge",
  33. detail: {
  34. valueAnimation: true,
  35. },
  36. progress: {
  37. show: true,
  38. },
  39. data: [
  40. {
  41. value: 60,
  42. name: "SCORE",
  43. },
  44. ],
  45. },
  46. ],
  47. });
  48. });
  49. },
  50. };
  51. </script>
  52. <style>
  53. #eleven {
  54. height: 5.125rem;
  55. }
  56. </style>
         14.关系图代码
  1. <template>
  2. <div>
  3. <div id="twelve">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted, reactive } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. let data = reactive({
  12. list: [
  13. //创建节点数据
  14. {
  15. name: "韦小宝",
  16. id: "1",
  17. symbolSize: 30, //节点大小
  18. symbol: "circle", //节点形状,
  19. },
  20. {
  21. name: "方怡",
  22. id: "2",
  23. symbolSize: 30, //节点大小
  24. symbol: "circle", //节点形状,
  25. },
  26. {
  27. name: "双儿",
  28. id: "3",
  29. symbolSize: 30, //节点大小
  30. symbol: "circle", //节点形状,
  31. },
  32. {
  33. name: "茅十八",
  34. id: "4",
  35. symbolSize: 30, //节点大小
  36. symbol: "circle", //节点形状,
  37. },
  38. {
  39. name: "吴六奇",
  40. id: "5",
  41. symbolSize: 30, //节点大小
  42. symbol: "circle", //节点形状,
  43. },
  44. ],
  45. num: [
  46. {
  47. source: "1", //边的源节点名称的字符串
  48. target: "2", //边的目标节点名称的字符串
  49. relation: {
  50. name: "同学",
  51. id: "1",
  52. },
  53. },
  54. {
  55. source: "1",
  56. target: "3",
  57. relation: {
  58. name: "朋友",
  59. id: "1",
  60. },
  61. },
  62. {
  63. source: "1",
  64. target: "4",
  65. relation: {
  66. name: "同事",
  67. id: "1",
  68. },
  69. },
  70. {
  71. source: "4",
  72. target: "1",
  73. relation: {
  74. name: "兄弟",
  75. id: "1",
  76. },
  77. },
  78. {
  79. source: "3",
  80. target: "5",
  81. relation: {
  82. name: "陌生人",
  83. id: "1",
  84. },
  85. },
  86. ],
  87. });
  88. onMounted(() => {
  89. let echarts = $echarts.init(document.getElementById("twelve"));
  90. echarts.setOption({
  91. title: {
  92. text: "关系图",
  93. left: "center",
  94. textStyle: {
  95. color: "#fff",
  96. textShadowBlur: 10,
  97. textShadowColor: "#33ffff",
  98. },
  99. },
  100. series: [
  101. {
  102. type: "graph", //图标类型为关系图用于展现节点以及节点之间的关系数据
  103. layout: "force", //图的布局 引导布局
  104. data: data.list,
  105. itemStyle: {
  106. //节点的样式
  107. color: "#95dcb2",
  108. },
  109. label: {
  110. show: true,
  111. position: "bottom", //位置底部
  112. distance: 5, //距离图形元素的距离
  113. fontSize: 18,
  114. align: "center", //文字水平对齐方式
  115. },
  116. force: {
  117. //设置间距
  118. repulsion: 50, //点之间的距离
  119. gravity: 0.01, //设置距离中心点位置
  120. edgeLength: 100, //边的两个节点之间的距离
  121. },
  122. links: data.num, //节点间的关系数据
  123. edgeLabel: {
  124. //标签
  125. show: true,
  126. position: "middle", //标签位置线的中点
  127. fontSize: 12,
  128. formatter: (params) => {
  129. //标签内容格式设置内容
  130. return params.data.relation.name;
  131. },
  132. },
  133. edgeSymbol: ["circle", "arrow"], //边两边的类型
  134. autoCurveness: 0.01, //针对节点之间存在多边的情况,自动计算各边曲率
  135. },
  136. ],
  137. });
  138. });
  139. return {
  140. data,
  141. };
  142. },
  143. };
  144. </script>
  145. <style>
  146. #twelve {
  147. height: 5.125rem;
  148. }
  149. </style>
        15.数据区域缩放代码
  1. <template>
  2. <div>
  3. <div id="thirteen">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("thirteen"));
  13. echarts.setOption({
  14. title: {
  15. text: "数据区域缩放",
  16. left: "center",
  17. textStyle: {
  18. color: "#fff",
  19. textShadowBlur: 10,
  20. textShadowColor: "#33ffff",
  21. },
  22. },
  23. grid: {
  24. // bottom: "10%",
  25. left: "1%",
  26. right: "20%",
  27. containLabel: true,
  28. },
  29. toolbox: {
  30. iconStyle: {
  31. borderColor: "#fff",
  32. },
  33. feature: {
  34. dataView: { readOnly: false },
  35. magicType: { type: ["bar", "line"] },
  36. restore: {},
  37. saveAsImage: {},
  38. },
  39. },
  40. tooltip: {
  41. trigger: "axis",
  42. },
  43. legend: {},
  44. xAxis: {
  45. type: "category",
  46. axisLine: {
  47. lineStyle: {
  48. color: "#fff",
  49. },
  50. },
  51. data: [
  52. "星期一",
  53. "星期二",
  54. "星期三",
  55. "星期四",
  56. "星期五",
  57. "星期六",
  58. "星期天",
  59. ],
  60. },
  61. yAxis: {
  62. value: "category",
  63. axisLine: {
  64. lineStyle: {
  65. color: "#fff",
  66. },
  67. },
  68. },
  69. series: [
  70. {
  71. type: "line",
  72. data: [150, 230, 224, 218, 135, 147, 260],
  73. smooth: true,
  74. showSymbol: false,
  75. lineStyle: {
  76. color: "#fff",
  77. },
  78. markPoint: {
  79. data: [
  80. {
  81. type: "max",
  82. value: "最大值",
  83. },
  84. {
  85. type: "min",
  86. value: "最小值",
  87. },
  88. ],
  89. },
  90. markLine: {
  91. data: [
  92. {
  93. type: "average",
  94. value: "平均值",
  95. },
  96. ],
  97. },
  98. },
  99. ],
  100. dataZoom: [
  101. {
  102. type: "slider",
  103. xAxisIndex: 0,
  104. filterMode: "none",
  105. },
  106. {
  107. type: "slider",
  108. yAxisIndex: 0,
  109. filterMode: "none",
  110. },
  111. ],
  112. });
  113. });
  114. },
  115. };
  116. </script>
  117. <style>
  118. #thirteen {
  119. height: 5.125rem;
  120. }
  121. </style>
         16.数据排序代码
  1. <template>
  2. <div>
  3. <div id="fifteen">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("fifteen"));
  13. echarts.setOption({
  14. title: {
  15. text: "数据排序",
  16. left: "center",
  17. textStyle: {
  18. color: "#fff",
  19. textShadowBlur: 10,
  20. textShadowColor: "#33ffff",
  21. },
  22. },
  23. dataset: [
  24. {
  25. dimensions: ["分类", "数量"],
  26. source: [
  27. ["美食", 123],
  28. ["日化", 98],
  29. ["熟食", 231],
  30. ["数码", 223],
  31. ["蔬菜", 25],
  32. ["杂项", 19],
  33. ],
  34. },
  35. {
  36. transform: {
  37. type: "sort",
  38. config: { dimension: "数量", order: "desc" },
  39. },
  40. },
  41. ],
  42. grid: {
  43. bottom: "1%",
  44. containLabel: true,
  45. },
  46. tooltip: {
  47. trigger: "axis",
  48. },
  49. legend: {},
  50. toolbox: {
  51. iconStyle: {
  52. borderColor: "white",
  53. },
  54. show: true, //是否显示工具栏组件,默认显示true
  55. feature: {
  56. dataView: { readOnly: false },
  57. magicType: { type: ["bar", "line"] },
  58. restore: {},
  59. saveAsImage: {},
  60. },
  61. },
  62. xAxis: {
  63. type: "category",
  64. axisLine: {
  65. lineStyle: {
  66. color: "white",
  67. },
  68. },
  69. axisLabel: {
  70. interval: 0,
  71. rotate: 30,
  72. },
  73. },
  74. yAxis: {
  75. axisLine: {
  76. lineStyle: {
  77. color: "white",
  78. },
  79. },
  80. },
  81. series: [
  82. {
  83. type: "bar",
  84. encode: {
  85. x: "分类",
  86. y: "数量",
  87. },
  88. markPoint: {
  89. data: [
  90. {
  91. type: "max",
  92. value: "最大值",
  93. label: { color: "#f00" },
  94. },
  95. {
  96. type: "min",
  97. value: "最小值",
  98. label: { color: "#f00" },
  99. },
  100. ],
  101. },
  102. itemStyle: {
  103. barBorderRadius: [50, 0, 90, 0],
  104. color: new $echarts.graphic.LinearGradient(0, 0, 1, 0, [
  105. {
  106. offset: 0,
  107. color: "#ff0",
  108. },
  109. {
  110. offset: 0.5,
  111. color: "#f90",
  112. },
  113. {
  114. offset: 1,
  115. color: "#0f0",
  116. },
  117. ]),
  118. },
  119. datasetIndex: 1,
  120. },
  121. ],
  122. });
  123. });
  124. },
  125. };
  126. </script>
  127. <style>
  128. #fifteen {
  129. height: 5.125rem;
  130. }
  131. </style>
         17.雷达图代码
  1. <template>
  2. <div>
  3. <div id="six">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. onMounted(() => {
  12. let echarts = $echarts.init(document.getElementById("six"));
  13. echarts.setOption({
  14. title: {
  15. text: "雷达图",
  16. left: "center",
  17. textStyle: {
  18. color: "#fff",
  19. textShadowBlur: 10,
  20. textShadowColor: "#fff",
  21. },
  22. },
  23. radar: {
  24. indicator: [
  25. { name: "蔬菜" },
  26. { name: "水果" },
  27. { name: "熟食" },
  28. { name: "数码" },
  29. { name: "家电" },
  30. { name: "日化" },
  31. ],
  32. center: ["50%", "55%"],
  33. radius: "60%",
  34. startAngle: 90,
  35. splitNumber: 6,
  36. // shape: "circle",
  37. splitArea: {
  38. areaStyle: {
  39. color: ["#77EADF", "#26C3BE", "#64AFE9", "#428BD4"],
  40. shadowColor: "rgba(0, 0, 0, 0.2)",
  41. shadowBlur: 10,
  42. },
  43. },
  44. axisName: {
  45. formatter: "[{value}]",
  46. color: "#fff",
  47. },
  48. // axisTick: {
  49. // show: true,
  50. // lineStyle: {
  51. // color: "rgba(255, 255, 255, 0.8)",
  52. // },
  53. // },
  54. },
  55. series: [
  56. {
  57. type: "radar",
  58. symbol: "rect",
  59. data: [
  60. {
  61. value: [4000, 2000, 5000, 9000, 7000, 8000],
  62. name: "销量",
  63. lineStyle: "dashed",
  64. symbolSize: 6,
  65. areaStyle: {
  66. color: "rgba(255, 228, 52, 0.6)",
  67. },
  68. },
  69. ],
  70. },
  71. ],
  72. });
  73. });
  74. },
  75. };
  76. </script>
  77. <style>
  78. #six {
  79. height: 5.125rem;
  80. }
  81. </style>
        18.树形图代码 
  1. <template>
  2. <div>
  3. <div id="fourteen">你好呀</div>
  4. </div>
  5. </template>
  6. <script>
  7. import { inject, onMounted, reactive } from "vue";
  8. export default {
  9. setup() {
  10. let $echarts = inject("echarts");
  11. let data = reactive({
  12. name: "层级1", // 节点的名称,当前节点 label 对应的文本
  13. children: [
  14. {
  15. name: "层级2",
  16. children: [
  17. {
  18. name: "层级3-1",
  19. children: [
  20. //子节点
  21. { name: "数据1", value: 3938 }, // value 值,只在 tooltip 中显示
  22. { name: "数据2", value: 3812 },
  23. { name: "数据3", value: 6714 },
  24. { name: "数据4", value: 743 },
  25. ],
  26. },
  27. {
  28. name: "层级3-2",
  29. children: [
  30. { name: "数据1", value: 3534 },
  31. { name: "数据2", value: 5731 },
  32. { name: "数据3", value: 7840 },
  33. { name: "数据4", value: 5914 },
  34. { name: "数据5", value: 3416 },
  35. ],
  36. },
  37. ],
  38. },
  39. ],
  40. });
  41. onMounted(() => {
  42. let echarts = $echarts.init(document.getElementById("fourteen"));
  43. echarts.setOption({
  44. title: {
  45. text: "树形图",
  46. left: "center",
  47. textStyle: {
  48. color: "#fff",
  49. textShadowBlur: 10,
  50. textShadowColor: "#33ffff",
  51. },
  52. },
  53. grid: {},
  54. tooltip: {
  55. trigger: "item",
  56. },
  57. legend: {},
  58. series: [
  59. {
  60. type: "tree",
  61. data: [data],
  62. symbolSize: 20,
  63. orient: "LR", //树图中 正交布局 的方向 // 水平 方向的 从左到右'LR',从右到左'RL'; // 以及垂直方向的 从上到下'TB',从下到上'BT'
  64. label: {
  65. position: "bottom",
  66. // rotate: 90,
  67. // verticalAlign: "middle",
  68. // align: "right",
  69. },
  70. leaves: {
  71. label: {
  72. position: "top",
  73. // verticalAlign: "middle",
  74. // align: "left",
  75. },
  76. },
  77. emphasis: {
  78. focus: "descendant",
  79. },
  80. expandAndCollapse: true,
  81. animationDuration: 550,
  82. animationDurationUpdate: 750,
  83. },
  84. ],
  85. });
  86. });
  87. return {
  88. data,
  89. };
  90. },
  91. };
  92. </script>
  93. <style>
  94. #fourteen {
  95. height: 5.125rem;
  96. }
  97. </style>
        19.世界地图代码 
  1. <template>
  2. <div class="body">
  3. <header>
  4. <el-button-group class="ebg">
  5. <el-button type="primary" class="pri" @click="handleClick">
  6. <el-icon class="el-icon--left ei"><ArrowLeft /></el-icon>返回
  7. </el-button>
  8. </el-button-group>
  9. <!-- <span>世界地图</span> -->
  10. </header>
  11. <div id="worldMap"></div>
  12. </div>
  13. </template>
  14. <script>
  15. import axios from "axios";
  16. import { inject, onMounted, reactive } from "vue";
  17. import { useRouter } from "vue-router";
  18. export default {
  19. methods: {
  20. handleClick() {
  21. // 点击事件处理逻辑
  22. this.$router.push({ name: "index" });
  23. },
  24. },
  25. setup() {
  26. let $echarts = inject("echarts");
  27. let mapData = reactive({});
  28. let worldData = reactive({});
  29. let router = useRouter();
  30. async function getState() {
  31. mapData = await axios.get("/shoudu/data");
  32. worldData = await axios.get("/world/data");
  33. }
  34. onMounted(() => {
  35. getState().then(() => {
  36. let echarts = $echarts.init(document.getElementById("worldMap"));
  37. $echarts.registerMap("worldMap", worldData.data.worldData);
  38. // console.log(worldData.data.worldData.features);
  39. // const dataPoints = [];
  40. // for (let i = 0; i < worldData.data.worldData.features.length; i++) {
  41. // const feature = worldData.data.worldData.features[i];
  42. // const dataPoint = {
  43. // name: feature.properties.name,
  44. // value: feature.properties.cp,
  45. // };
  46. // dataPoints.push(dataPoint);
  47. // }
  48. // console.log(worldData.data.worldData.features[0].properties.name);
  49. // console.log(worldData.data.worldData.features[0].properties.cp);
  50. echarts.setOption({
  51. title: {
  52. text: "世界地图",
  53. left: "center",
  54. textStyle: {
  55. color: "#fff",
  56. fontSize: 25,
  57. textShadowBlur: 10,
  58. textShadowColor: "#3ff",
  59. },
  60. },
  61. tooltip: {
  62. trigger: "item",
  63. },
  64. geo: {
  65. map: "worldMap",
  66. roam: true,
  67. scaleLimit: {
  68. max: 5,
  69. min: 1,
  70. },
  71. label: {
  72. show: true,
  73. color: "#fff",
  74. fontSize: 10,
  75. },
  76. itemStyle: {
  77. areaColor: "#0099ff",
  78. },
  79. emphasis: {
  80. focus: "none",
  81. itemStyle: {
  82. areaColor: "#5f0",
  83. borderColor: "#0ff",
  84. shadowColor: "rgba(230,130,70,.5)",
  85. shadowBlur: 30,
  86. },
  87. },
  88. zoom: 3,
  89. center: [104, 35],
  90. },
  91. series: [
  92. {
  93. type: "effectScatter",
  94. symbolSize: 5,
  95. // map: "china",
  96. coordinateSystem: "geo",
  97. data: mapData.data.shouduData.shouDu,
  98. label: {
  99. show: true,
  100. formatter: function (params) {
  101. return params.name; // 城市名称
  102. },
  103. },
  104. rippleEffect: {
  105. number: 2,
  106. scale: 8,
  107. },
  108. itemStyle: {
  109. fontSize: 5,
  110. color: "red",
  111. show: true,
  112. },
  113. markLine: {
  114. silent: true,
  115. },
  116. },
  117. ],
  118. });
  119. echarts.on("click", function (params) {
  120. console.log(params);
  121. if (params.componentType === "geo") {
  122. if (params.componentIndex === 0) {
  123. if (params.name === "中国") {
  124. router.push({ name: "cities" });
  125. }
  126. }
  127. }
  128. });
  129. });
  130. });
  131. return {
  132. getState,
  133. mapData,
  134. worldData,
  135. };
  136. },
  137. };
  138. </script>
  139. <style>
  140. .body {
  141. background: url("@/assets/bg.jpg"), top center no-repeat;
  142. /* height: 100%; */
  143. }
  144. #worldMap {
  145. width: 100%;
  146. height: 11.2rem;
  147. }
  148. header {
  149. height: 1rem;
  150. width: 100%;
  151. /* background-color: rgba(0, 0, 255, 0.2); */
  152. }
  153. .pri {
  154. font-size: 0.3rem;
  155. background-color: transparent;
  156. border: none;
  157. margin-top: 0.3rem;
  158. }
  159. .pri:hover {
  160. background-color: transparent;
  161. }
  162. </style>
        20.中国城市地图代码 
  1. <template>
  2. <div class="body">
  3. <header>
  4. <el-button-group class="ebg">
  5. <el-button type="primary" class="pri" @click="handleClick">
  6. <el-icon class="el-icon--left ei"><ArrowLeft /></el-icon>返回
  7. </el-button>
  8. </el-button-group>
  9. </header>
  10. <div id="chinaContour"></div>
  11. </div>
  12. </template>
  13. <script>
  14. import axios from "axios";
  15. import { inject, onMounted, reactive } from "vue";
  16. export default {
  17. methods: {
  18. handleClick() {
  19. // 点击事件处理逻辑
  20. this.$router.push({ name: "world" });
  21. },
  22. },
  23. setup() {
  24. let $echarts = inject("echarts");
  25. let chinaContourData = reactive({});
  26. async function getState() {
  27. chinaContourData = await axios.get("/chinacontour/data");
  28. }
  29. onMounted(() => {
  30. getState().then(() => {
  31. let echarts = $echarts.init(document.getElementById("chinaContour"));
  32. $echarts.registerMap(
  33. "chinaContour",
  34. chinaContourData.data.chinaContourData
  35. );
  36. console.log(chinaContourData.data.chinaContourData);
  37. // console.log(chinaCitiesData.data.chinaCitiesData.features[0].properties.name);
  38. // console.log(chinaCitiesData.data.chinaCitiesData.features[0].properties.cp);
  39. const dataPoints = [];
  40. for (
  41. let i = 0;
  42. i < chinaContourData.data.chinaContourData.features.length;
  43. i++
  44. ) {
  45. const feature = chinaContourData.data.chinaContourData.features[i];
  46. const dataPoint = {
  47. name: feature.properties.name,
  48. value: feature.properties.cp,
  49. };
  50. dataPoints.push(dataPoint);
  51. }
  52. echarts.setOption({
  53. title: {
  54. text: "中国城市地图",
  55. left: "center",
  56. textStyle: {
  57. color: "#fff",
  58. fontSize: 25,
  59. textShadowBlur: 10,
  60. textShadowColor: "#3ff",
  61. },
  62. },
  63. tooltip: {
  64. trigger: "item",
  65. },
  66. geo: {
  67. map: "chinaContour",
  68. roam: true,
  69. scaleLimit: {
  70. max: 5,
  71. min: 1,
  72. },
  73. label: {
  74. show: true,
  75. color: "#fff",
  76. fontSize: 10,
  77. },
  78. itemStyle: {
  79. areaColor: "#0099ff",
  80. },
  81. emphasis: {
  82. focus: "none",
  83. itemStyle: {
  84. areaColor: "#5f0",
  85. borderColor: "#0ff",
  86. shadowColor: "rgba(230,130,70,.5)",
  87. shadowBlur: 30,
  88. },
  89. },
  90. // zoom: 3,
  91. // center: [104, 35],
  92. },
  93. series: [
  94. {
  95. type: "effectScatter",
  96. symbolSize: 5,
  97. coordinateSystem: "geo",
  98. data: dataPoints,
  99. label: {
  100. show: true,
  101. formatter: function (params) {
  102. return params.name; // 城市名称
  103. },
  104. },
  105. rippleEffect: {
  106. number: 2,
  107. scale: 8,
  108. },
  109. itemStyle: {
  110. fontSize: 5,
  111. color: "red",
  112. show: true,
  113. },
  114. markLine: {
  115. silent: true,
  116. },
  117. },
  118. ],
  119. });
  120. });
  121. });
  122. return {
  123. getState,
  124. chinaContourData,
  125. };
  126. },
  127. };
  128. </script>
  129. <style>
  130. .body {
  131. background: url("@/assets/bg.jpg"), top center no-repeat;
  132. /* height: 100%; */
  133. }
  134. #chinaContour {
  135. width: 100%;
  136. height: 11.2rem;
  137. }
  138. header {
  139. height: 1rem;
  140. width: 100%;
  141. /* background-color: rgba(0, 0, 255, 0.2); */
  142. }
  143. .pri {
  144. font-size: 0.3rem;
  145. background-color: transparent;
  146. border: none;
  147. margin-top: 0.3rem;
  148. }
  149. .pri:hover {
  150. background-color: transparent;
  151. }
  152. </style>
        21.中国省份地图(34个)
  1. <template>
  2. <div>
  3. <header>
  4. <el-button-group class="ebg">
  5. <el-button type="primary" class="pri" @click="handleClick">
  6. <el-icon class="el-icon--left ei"><ArrowLeft /></el-icon>返回
  7. </el-button>
  8. </el-button-group>
  9. <!-- <span>世界地图</span> -->
  10. </header>
  11. <div id="beiMap">你好呀</div>
  12. </div>
  13. </template>
  14. <script>
  15. import { inject, onMounted } from "vue";
  16. import beijing from "../../../public/map/province/beijing.json";
  17. export default {
  18. methods: {
  19. handleClick() {
  20. // 点击事件处理逻辑
  21. this.$router.push({ name: "page" });
  22. },
  23. },
  24. setup() {
  25. let $echarts = inject("echarts");
  26. onMounted(() => {
  27. let echarts = $echarts.init(document.getElementById("beiMap"));
  28. $echarts.registerMap("beiMap", beijing);
  29. echarts.setOption({
  30. title: {
  31. text: "北京市地图",
  32. left: "center",
  33. textStyle: {
  34. color: "#fff",
  35. textShadowBlur: 10,
  36. textShadowColor: "#3ff",
  37. },
  38. },
  39. tooltip: {
  40. trigger: "item",
  41. },
  42. legend: {},
  43. geo: {
  44. map: "beiMap",
  45. roam: true,
  46. scaleLimit: {
  47. max: 3,
  48. min: 1.2,
  49. },
  50. layoutCenter: ["50%", "50%"],
  51. layoutSize: "70%", // 调整地图的尺寸
  52. zoom: 1.2,
  53. label: {
  54. //地图上显示文字提示信息
  55. show: true,
  56. color: "#ffffff",
  57. fontSize: 10, //字体大小
  58. },
  59. // center: [108.956239, 34.268309],
  60. itemStyle: {
  61. areaColor: "#0099ff",
  62. },
  63. emphasis: {
  64. focus: "none",
  65. itemStyle: {
  66. areaColor: "#fff",
  67. borderColor: "#00ffff",
  68. shadowColor: "rgba(230,130,70,0.5)",
  69. shadowBlur: 30,
  70. },
  71. },
  72. },
  73. series: [
  74. {
  75. type: "effectScatter",
  76. symbolSize: 10,
  77. coordinateSystem: "geo",
  78. data: [{ name: "北京市", value: [116.412812, 39.919336] }],
  79. rippleEffect: {
  80. number: 2,
  81. scale: 5,
  82. },
  83. itemStyle: {
  84. color: "#f00",
  85. },
  86. },
  87. ],
  88. });
  89. });
  90. },
  91. };
  92. </script>
  93. <style>
  94. #beiMap {
  95. height: 11.1rem;
  96. /* background-color: white; */
  97. }
  98. header {
  99. height: 1rem;
  100. width: 100%;
  101. /* background-color: rgba(0, 0, 255, 0.2); */
  102. }
  103. .pri {
  104. font-size: 0.3rem;
  105. background-color: transparent;
  106. border: none;
  107. margin-top: 0.3rem;
  108. }
  109. .pri:hover {
  110. background-color: transparent;
  111. }
  112. </style>

八、部分代码解析 

        i.引入组件以及插槽的作用
  1. <section class="left">
  2. <itemPage>
  3. <itemOne />
  4. </itemPage>
  5. <itemPage>
  6. <itemTwo />
  7. </itemPage>
  8. </section>

        以上这段代码创建了一个名为"left"的部分,并在其中使用了itemPage组件来展示其他两个组件。这需要我们itemPage组件中加入一个插槽标签(<slot></slot>),插槽在组件化开发中起到了构建灵活、可定制和可复用组件的重要作用。它允许父组件向子组件提供动态内容,并实现更灵活的布局和展示。同时在script标签中引入该组件来使用,如下:

  1. <script>
  2. import itemPage from "@/components/itemPage.vue";
  3. import itemOne from "@/components/itemOne.vue";
  4. import itemTwo from "@/components/itemTwo.vue";
  5. export default {
  6. components: {
  7. itemPage,
  8. itemOne,
  9. itemTwo,
  10. },
  11. };
  12. </script>

        ii. 数据中提取特定的信息
  1. <script>
  2. import axios from "axios";
  3. import { inject, onMounted, reactive } from "vue";
  4. export default {
  5. setup() {
  6. let $echarts = inject("echarts");
  7. let chinaContourData = reactive({});
  8. async function getState() {
  9. chinaContourData = await axios.get("/chinacontour/data");
  10. }
  11. onMounted(() => {
  12. getState().then(() => {
  13. let echarts = $echarts.init(document.getElementById("chinaContour"));
  14. $echarts.registerMap(
  15. "chinaContour",
  16. chinaContourData.data.chinaContourData
  17. );
  18. const dataPoints = [];
  19. for (
  20. let i = 0;
  21. i < chinaContourData.data.chinaContourData.features.length;
  22. i++
  23. ) {
  24. const feature = chinaContourData.data.chinaContourData.features[i];
  25. const dataPoint = {
  26. name: feature.properties.name,
  27. value: feature.properties.cp,
  28. };
  29. dataPoints.push(dataPoint);
  30. }
  31. echarts.setOption({
  32. title: {
  33. text: "中国城市地图",
  34. },
  35. },
  36. tooltip: {},
  37. geo: {
  38. map: "chinaContour",
  39. roam: true,
  40. series: [
  41. {
  42. type: "effectScatter",
  43. coordinateSystem: "geo",
  44. data: dataPoints,
  45. rippleEffect: {
  46. number: 2,
  47. scale: 8,
  48. },
  49. },
  50. ],
  51. });
  52. });
  53. });
  54. return {
  55. getState,
  56. chinaContourData,
  57. };
  58. },
  59. };
  60. </script>

        以上当中 const dataPoints = []...的作用是从chinaContourData数据中提取特定的信息,并将这些信息转换为一个包含多个数据点的数组dataPoints,然后再赋值给echarts.setOption({series: [data: dataPoints,]})以便更加方便地渲染出来。

具体的步骤如下:

        1.创建一个空数组dataPoints,用于存储数据点。

        2.使用for循环遍历 chinaContourData.data.chinaContourData.features数组的每个元素。

        3.在每次循环中,从 chinaContourData.data.chinaContourData.features数组中获取当前元素,并将其赋值给变量features。

        4.创建一个对象dataPoint,其中包括两个属性:

                》name属性:赋值为 feature.properties.name,表示数据点的名称。

                》value属性:赋值为 feature.properties.cp,表示数据点的值。

        5.将dataPoint对象添加到dataPoints数组中。

        6.循环结束后,dataPoints数组将包含多个数据点对象,每个对象都有一个名称和一个值。

        iii.使用ECharts图表库中的echarts.on方法来监听点击事件
  1. echarts.on("click", function (params) {
  2. if (params.componentType === "geo") {
  3. if (params.componentIndex === 0) {
  4. var clickedProvince = params.name;
  5. console.log(clickedProvince);
  6. if (provinceRoutes.hasOwnProperty(clickedProvince)) {
  7. router.push({ name: provinceRoutes[clickedProvince] });
  8. }
  9. }
  10. }
  11. });
  12. const provinceRoutes = {
  13. 广东: "guangdong",
  14. 广西: "guangxi",
  15. 安徽: "anhui",
  16. 新疆: "xinjiang",
  17. 西藏: "xizang",
  18. 内蒙古: "neimenggu",
  19. 宁夏: "ningxia",
  20. 青海: "qinghai",
  21. 甘肃: "gansu",
  22. 四川: "sichuan",
  23. 重庆: "chongqing",
  24. 云南: "yunnan",
  25. 贵州: "guizhou",
  26. 陕西: "shanxi",
  27. 山西: "shanXi",
  28. 湖南: "hunan",
  29. 湖北: "hubei",
  30. 河南: "henan",
  31. 河北: "hebei",
  32. 山东: "shandong",
  33. 北京: "beijing",
  34. 天津: "tianjin",
  35. 江西: "jiangxi",
  36. 福建: "fujian",
  37. 台湾: "taiwan",
  38. 香港: "xianggang",
  39. 澳门: "aomen",
  40. 海南: "hainan",
  41. 浙江: "zhejiang",
  42. 上海: "shanghai",
  43. 江苏: "jiangsu",
  44. 辽宁: "liaoning",
  45. 吉林: "jilin",
  46. 黑龙江: "heilongjiang",
  47. };

        以上代码是一个JavaScript的事件监听器,它使用ECharts图表库中的echarts.on方法来监听点击事件。当用户点击ECharts图表中的元素时,该事件监听器会被触发。

        在事件处理函数中,首先判断被点击的组件类型是否为地理组件,即判断params.componentType是否为"geo"。然后再判断被点击的地理组件的索引是否为0,即判断params.componentIndex是否为0。这样的判断是为了确定用户点击的是否是地图上的某个省份。

        如果上述条件满足,那么代码会获取被点击的省份名称params.name,并将其打印到控制台中。

        接下来,代码会检查provinceRoutes对象中是否存在键名为clickedProvince的属性。如果存在,则会使用router.push方法进行页面路由跳转,跳转到provinceRoutes[clickedProvince]指定的目标路由。

  provinceRoutes对象是一个映射,将省份名称映射为相应的路由名称。例如,如果点击了"广东"省份,代码会将路由跳转到名为"guangdong"的目标页面。

        总而言之,这段代码实现了在地图上点击某个省份时,根据省份名称进行页面路由跳转的功能。

        当然,我们也可以用最棒(笨)的方法,如以下:

  1. echarts.on("click", function (params) {
  2. console.log(params);
  3. if (params.componentType === "geo") {
  4. if (params.componentIndex === 0) {
  5. if (params.name === "广东") {
  6. router.push({ name: "cities" });
  7. }else if (params.name === "广西") {
  8. router.push({ name: "cities" });
  9. }else if (params.name === "北京") {
  10. router.push({ name: "cities" });
  11. }else if ......
  12. }
  13. }
  14. });

九、容易忘记点(复习点)

        i.子路由中path中不用加"/"

       ii.Vue3.0中,使用了Compositon API,this的使用方式发生了一些变化。在Compositon API,可以使用ref和reactive创建响应式数据,使用computed创建计算属性,以及使用watch监听数据的变化。此外,使用setup()函数来编写组件罗辑,该函数接收props和context作为参数,不在使用this。

        iii.访问计算属性computed的值需要使用”.value”。

        iv.设置数据请求方法,不要忘了return

十、页面截屏功能分析

(图一)

     点击图一当中的城市销量的中国地图的每个省份可实现跳转查看到当前点击的省份的详细省份地图,例如点击其中的广东省随处范围可跳转查看该省份的详细城市(均可缩放大小),如以下图二:

(图二)

     点击北京市可查看跳转到北京市的详细地图,如以下图三:

(图三)

     以下图四、图五、图六是Echarts当中的常用大屏数据可视化图表是“点击此处查看更多”后跳转到下一个页面所展示出来的:

(图四)

(图五)

(图六)

     以下图七是是点击“下一页”后跳转到下一个页面所展示出来的世界地图(可缩放大小),其中展示世界上所有国家的名称以及展示该国家对应的国家首都:

(图七)

     在图七当中世界地图当中点击随处点击一个国家地图可跳转到对应的国家的详细城市地图(均可缩放大小),如点击图中的中国随处一处,则跳转到中国城市地图(均可缩放大小)(如下图)。

(图八)

十一:源码地址

https://gitee.com/AChong_0427/echarts

<到此结束,感谢列位收看>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/406690
推荐阅读
相关标签
  

闽ICP备14008679号