• Echarts图表 多表联动及图表数据还原


    项目场景:

    提示:多表联动、地市下区县数据联动、图表数据还原

    例如:


    需求描述

    需求一:例如点击南昌市展示该市下所有的区县的系统总数,同时【部门图表】展示对应南昌市下所有区下部门系统数量排行前15;点击南昌市某个区县,【部门图表】展示对于某个区县下所有区下部门系统数量排行前15;

    需求二:点击重置按钮,一切回到最初的起点


    需求分析:

    需求一代码:

    需求二代码


    解决方案:

    代码一:

    1. <template>
    2. <div :id="echartId" :style="{width: '100%', height: '100%'}">div>
    3. template>
    4. <script>
    5. export default {
    6. name: "EchartPic",
    7. props:{
    8. echartId: '',
    9. echartData:[]
    10. },
    11. data() {
    12. return {};
    13. },
    14. mounted() {
    15. this.drawLine();
    16. },
    17. methods: {
    18. drawLine() {
    19. let data = new Array();
    20. for (let x of this.echartData) {
    21. let y = {
    22. name : x.name,
    23. value : x.number
    24. }
    25. data.push(y)
    26. }
    27. var echarts = require("echarts");
    28. var myChart = echarts.init(document.getElementById(this.echartId));
    29. let that = this
    30. myChart.setOption({
    31. grid: {
    32. left: "6%",
    33. right: "4%",
    34. bottom: "10%",
    35. top: "8%",
    36. containLabel: true
    37. },
    38. tooltip: {
    39. //提示框,可以在全局也可以在
    40. trigger: "item", //提示框的样式
    41. formatter: "{a}
      {b}: {c} ({d}%)"
      ,
    42. color: "#000", //提示框的背景色
    43. textStyle: {
    44. //提示的字体样式
    45. color: "#fff"
    46. }
    47. },
    48. toolbox: {
    49. show: true,
    50. feature: {
    51. mark: { show: true },
    52. dataView: { show: true, readOnly: false },
    53. myTool1: {
    54. show: true,
    55. title: "还原",
    56. icon:
    57. "M509.166933 230.4A281.6 281.6 0 1 0 793.6 512a280.302933 280.302933 0 0 0-65.672533-180.770133 25.6 25.6 0 0 1 39.253333-32.904534A331.502933 331.502933 0 0 1 844.8 512c0 183.808-148.992 332.8-332.8 332.8S179.2 695.808 179.2 512c0-177.493333 138.922667-322.491733 313.924267-332.288l-45.056-45.056a25.6 25.6 0 1 1 36.181333-36.215467l96.5632 96.529067a25.6 25.6 0 0 1 0 36.215467l-96.5632 96.529066a25.6 25.6 0 1 1-36.181333-36.181333l61.098666-61.098667z",
    58. onclick: () => {
    59. if(that.echartId == 'myChart1'){
    60. that.$emit("getSystemCityData");
    61. }else if(that.echartId == 'myChart3'){
    62. that.$emit("getCatalogCityData");
    63. }
    64. },
    65. },
    66. saveAsImage: { show: true }
    67. }
    68. },
    69. series: [
    70. {
    71. name: "数量",
    72. type: "pie", //环形图的type和饼图相同
    73. radius: ["50%", "70%"], //饼图的半径,第一个为内半径,第二个为外半径
    74. avoidLabelOverlap: false,
    75. color: ["#02cab3", "#4885ff", "#fec67c", "#54c2fc", "#9991f6"],
    76. label: {
    77. normal: {
    78. //正常的样式
    79. show: true,
    80. position: "left"
    81. },
    82. emphasis: {
    83. //选中时候的样式
    84. show: true,
    85. textStyle: {
    86. fontSize: "16",
    87. fontWeight: "bold"
    88. }
    89. }
    90. }, //提示文字
    91. labelLine: {
    92. normal: {
    93. show: false
    94. }
    95. },
    96. data: data
    97. }
    98. ]
    99. });
    100. myChart.on('click', function(params) {
    101. if(that.echartId == 'myChart1'){
    102. that.$emit("getSystemCityData", params);
    103. }else if(that.echartId == 'myChart3'){
    104. that.$emit("getCatalogCityData", params);
    105. }
    106. });
    107. window.addEventListener("resize", function () {
    108. myChart.resize();
    109. });
    110. }
    111. }
    112. };
    113. script>
    114. <style scoped="true">
    115. style>

    代码二:

    1. <template>
    2. <div class="mainBox" style="height: 950px;background-color: #fff;">
    3. <div style="padding-top: 10px">
    4. <el-row :gutter="100">
    5. <el-col :span="6" v-for="item in titleData" :key="item.dict_key">
    6. <div :class="item.className">
    7. <el-row>
    8. <el-col :span="10">
    9. <div class="iconCircle">
    10. <i class="el-icon-postcard">i>
    11. div>
    12. el-col>
    13. <el-col :span="14">
    14. <div class="echartsTitleContent">
    15. <div>{{item.title}}div>
    16. <div>{{item.number}}div>
    17. div>
    18. el-col>
    19. el-row>
    20. div>
    21. el-col>
    22. el-row>
    23. div>
    24. <div class="linebox">
    25. <div>系统div>
    26. div>
    27. <div style="margin-top: 20px;">
    28. <el-row :gutter="10">
    29. <el-col :span="12">
    30. <div class="echartsTopBox">
    31. <div class="echartsTopTitle">地市div>
    32. <div class="echartsBox">
    33. <EchartPic echartId="myChart1" :echartData="systemCity" @getSystemCityData="systemCityMethod" :key="echartKey1"/>
    34. div>
    35. div>
    36. el-col>
    37. <el-col :span="12">
    38. <div class="echartsTopBox">
    39. <div class="echartsTopTitle">部门div>
    40. <div class="echartsBox" style="padding: 0px 10px 10px 10px;">
    41. <EchartBar echartId="myChart2" :echartData="systemDept" @getSystemDept="systemDeptMethod" :key="echartKey2"/>
    42. div>
    43. div>
    44. el-col>
    45. el-row>
    46. div>
    47. <div class="linebox">
    48. <div>资源目录div>
    49. div>
    50. <div style="margin-top: 20px;">
    51. <el-row :gutter="10">
    52. <el-col :span="12">
    53. <div class="echartsBottomBox">
    54. <div class="echartsTopTitle">地市div>
    55. <div class="echartsBoxBottom">
    56. <EchartPic echartId="myChart3" :echartData="resourceCity" @getCatalogCityData="resourceCityMethod" :key="echartKey3"/>
    57. div>
    58. div>
    59. el-col>
    60. <el-col :span="12">
    61. <div class="echartsBottomBox">
    62. <div class="echartsTopTitle">部门div>
    63. <div class="echartsBoxBottom">
    64. <EchartBar echartId="myChart4" :echartData="resourceDept" @getCatalogDeptData="resourceDeptMethod" :key="echartKey4"/>
    65. div>
    66. div>
    67. el-col>
    68. el-row>
    69. div>
    70. div>
    71. template>
    72. <script>
    73. import {getDataList,getSystemDept,getResourceDept,getResourceCity,getSystemCity} from "@/api/homePage/index";
    74. import EchartBar from "@/components/echarts/echartBar";
    75. import EchartPic from "@/components/echarts/echartPic";
    76. import * as echarts from "echarts";
    77. export default {
    78. name: "homePage",
    79. components: {
    80. EchartBar,
    81. EchartPic,
    82. },
    83. data() {
    84. return {
    85. titleData: [],
    86. systemDept:[],
    87. systemCity:[],
    88. resourceDept:[],
    89. resourceCity:[],
    90. echartKey1:0,
    91. echartKey2:0,
    92. echartKey3:0,
    93. echartKey4:0,
    94. };
    95. },
    96. created() {
    97. },
    98. mounted() {
    99. this.loadCountNum();
    100. },
    101. methods: {
    102. loadCountNum() {
    103. getDataList().then(res => {
    104. let arry = ['echartsTitleBox1',' echartsTitleBox2','echartsTitleBox3','echartsTitleBox4']
    105. res.data.forEach((item,index) =>{
    106. item.className = arry[index] //拼接class值
    107. if(item.name == 'cityCount'){
    108. item.title = '地市'
    109. }else if(item.name == 'deptCount'){
    110. item.title = '部门'
    111. }else if(item.name == 'systemCount'){
    112. item.title = '系统'
    113. }else if(item.name == 'resoureCount'){
    114. item.title = '资源目录'
    115. }
    116. })
    117. this.titleData = res.data
    118. });
    119. this.systemCityMethod();
    120. this.systemDeptMethod();
    121. this.resourceCityMethod();
    122. this.resourceDeptMethod();
    123. },
    124. systemCityMethod(param = ''){
    125. if(param == ''){
    126. getSystemCity().then(res => {
    127. this.systemCity = res.data
    128. this.echartKey1++
    129. });
    130. }else{
    131. getSystemCity(param.data.name).then(res => {
    132. //市区下可点击区县
    133. if(res.data.length != 0){
    134. this.systemCity = res.data
    135. this.echartKey1++
    136. }
    137. });
    138. }
    139. this.systemDeptMethod(param);
    140. },
    141. systemDeptMethod(param = ''){
    142. if(param == '') {
    143. getSystemDept().then(res => {
    144. this.systemDept = res.data
    145. this.echartKey2++
    146. });
    147. }else{
    148. getSystemDept(param.data.name).then(res => {
    149. if(res.data.length != 0) {
    150. this.systemDept = res.data
    151. this.echartKey2++
    152. }
    153. });
    154. }
    155. },
    156. resourceCityMethod(param = ''){
    157. if(param == '') {
    158. getResourceCity().then(res => {
    159. this.resourceCity = res.data
    160. this.echartKey3++
    161. });
    162. }else{
    163. getResourceCity(param.data.name).then(res => {
    164. if(res.data.length != 0) {
    165. this.resourceCity = res.data
    166. this.echartKey3++
    167. }
    168. });
    169. }
    170. this.resourceDeptMethod(param);
    171. },
    172. resourceDeptMethod(param = ''){
    173. if(param == '') {
    174. getResourceDept().then(res => {
    175. this.resourceDept = res.data
    176. this.echartKey4++
    177. });
    178. }else{
    179. getResourceDept(param.data.name).then(res => {
    180. if(res.data.length != 0) {
    181. this.resourceDept = res.data
    182. this.echartKey4++
    183. }
    184. });
    185. }
    186. },
    187. }
    188. };
    189. script>
    190. <style scoped="true">
    191. .mainBox {
    192. padding-top: 30px;
    193. padding-left: 30px;
    194. padding-right: 30px;
    195. }
    196. .echartsTitleBox1 {
    197. width: 100%;
    198. height: 110px;
    199. background-color: #00a0e9;
    200. border-radius: 10px;
    201. /*margin-top: 20px;*/
    202. }
    203. .echartsTitleBox2 {
    204. width: 100%;
    205. height: 110px;
    206. background-color: #13b5b1;
    207. border-radius: 10px;
    208. /*margin-top: 20px;*/
    209. }
    210. .echartsTitleBox3 {
    211. width: 100%;
    212. height: 110px;
    213. background-color: #00b7ee;
    214. border-radius: 10px;
    215. /*padding-top: 20px;*/
    216. }
    217. .echartsTitleBox4 {
    218. width: 100%;
    219. height: 110px;
    220. background-color: #f19149;
    221. border-radius: 10px;
    222. /*margin-top: 20px;*/
    223. }
    224. .iconCircle {
    225. width: 60px;
    226. height: 60px;
    227. line-height: 60px;
    228. border-radius: 50%;
    229. border: 1px solid #fff;
    230. margin: 0 auto;
    231. margin-top: 23px;
    232. display: flex;
    233. align-items: center;
    234. justify-content: center;
    235. }
    236. .iconCircle > i {
    237. font-size: 40px;
    238. color: #fff;
    239. }
    240. .echartsTitleContent {
    241. margin-top: 23px;
    242. }
    243. .echartsTitleContent div {
    244. font-size: 20px;
    245. color: #fff;
    246. }
    247. .echartsTitleContent div:last-child {
    248. margin-top: 5px;
    249. }
    250. .linebox {
    251. height: 60px;
    252. border-bottom: 1px solid #e5e5e5;
    253. /*margin-top: 10px;*/
    254. }
    255. .linebox div {
    256. font-size: 20px;
    257. height: 60px;
    258. width: 100px;
    259. text-align: center;
    260. line-height: 60px;
    261. border-bottom: 3px solid #0059c1;
    262. color: #0059c1;
    263. font-weight: 600;
    264. }
    265. .echartsTopBox {
    266. height: 300px;
    267. border: 1px solid #e5e5e5;
    268. border-radius: 10px;
    269. }
    270. .echartsBottomBox {
    271. height: 300px;
    272. border: 1px solid #e5e5e5;
    273. border-radius: 10px;
    274. }
    275. .echartsTopTitle {
    276. font-size: 18px;
    277. text-align: center;
    278. margin-top: 10px;
    279. font-weight: 600;
    280. }
    281. .echartsBox {
    282. width: 100%;
    283. height: 280px;
    284. }
    285. .echartsBoxBottom {
    286. width: 100%;
    287. height: 280px;
    288. }
    289. @media screen and (max-width: 1400px) and (min-width: 1300px) {
    290. .echartsBoxBottom {
    291. height: 250px;
    292. }
    293. .echartsBox {
    294. height: 250px;
    295. }
    296. }
    297. style>

  • 相关阅读:
    生活锦囊——优美小句
    把握鸿蒙生态机遇,共创智能应用未来
    洛谷C++简单题小练习day12—寻找最小值小程序
    mmcls 多标签模型部署在torch serve
    vw+rem自适应布局
    QML 带框最大化显示方法
    使用双动态令牌混合器学习全局和局部动态以进行视觉识别
    Python采集世界大学排行榜,做数据可视化,来看看你的大学上榜没
    Zabbix Proxy分布式监控
    sql注入(7), python 实现盲注爆破数据库名, 表名, 列名
  • 原文地址:https://blog.csdn.net/qq_38144121/article/details/126153066