• echarts的使用


    1. 普通版

    其实主要就是option1,option1就是画的图

    echats不能响应刷新,要想实时刷新监听刷新的值重新调用一下方法即可

    1. html
    2. class="echart" style="width: 100%;height: calc(100% - 130px)" ref="main1">
    3. js
    4. import * as echarts from "echarts";
    5. mounted() {
    6. this.initDayEcharts();
    7. },
    8. initDayEcharts() {
    9. const option1 = {
    10. legend: {
    11. textStyle: {
    12. color: '#ffffff'
    13. },
    14. y: 'bottom',
    15. },
    16. grid: {
    17. left: '5%',
    18. right: '5%',
    19. top: '10%',
    20. bottom: '15%',
    21. containLabel: true
    22. },
    23. xAxis: {
    24. type: 'value',
    25. axisLabel: {
    26. textStyle: {
    27. color: '#ffffff'
    28. }
    29. },
    30. },
    31. yAxis: {
    32. type: 'category',
    33. data: this.inAndOutWarehouseToday.name,
    34. axisLabel: {
    35. textStyle: {
    36. color: '#ffffff'
    37. }
    38. },
    39. },
    40. series: [
    41. {
    42. name: '入库数',
    43. type: 'bar',
    44. stack: 'total',
    45. label: {
    46. show: true
    47. },
    48. emphasis: {
    49. focus: 'series'
    50. },
    51. color: '#4F89FC',
    52. //动态条形图宽度
    53. barWidth: 20 ,
    54. data: this.inAndOutWarehouseToday.inNum
    55. },
    56. {
    57. name: '出库数',
    58. type: 'bar',
    59. stack: 'total',
    60. label: {
    61. show: true
    62. },
    63. emphasis: {
    64. focus: 'series'
    65. },
    66. color: '#A5DC65',
    67. barWidth: 20,
    68. data: this.inAndOutWarehouseToday.outNum
    69. }
    70. ]
    71. };
    72. // 获取DOM元素
    73. const main1 = echarts.init(this.$refs.main1);
    74. // 设置图表配置项和数据
    75. main1.setOption(option1);
    76. },

    2. 可跳转路径版+赋值版

    注意样式要给宽度,不然看不到

    1. "roadElectricity" style="flex: 1;height: 400px;width: 500px">
    2. js
    3. mounted() {
    4. this.getRouteElectromechanical()
    5. },
    6. methods: {
    7. a sync getRouteElectromechanical(params) {
    8. let queryParams = Object.assign({}, {name: '机电设施路段机电统计'}, params)
    9. let {data: data} = await commonListData(queryParams)
    10. console.log("data===",data)
    11. let res = data || []
    12. let roadElectricity = this.$echarts.init(document.getElementById('roadElectricity'))
    13. let option = {
    14. series: [
    15. {
    16. type: 'pie',
    17. data: [
    18. {
    19. value: 0,
    20. name: '服务区监控'
    21. },
    22. {
    23. value: 0,
    24. name: '路段监控系统'
    25. },
    26. {
    27. value: 0,
    28. name: '站级监控系统'
    29. },
    30. ],
    31. radius: '50%'
    32. }
    33. ]
    34. };
    35. if (res.length > 0) {
    36. console.log("机电设施路段机电统计=", res)
    37. option.series[0].data = res.map(item => Object.assign({}, {value: item.count, name: item.asset_type_name}))
    38. }
    39. roadElectricity.setOption(option)
    40. roadElectricity.on("click", (params) => {
    41. console.log('params=', params)
    42. this.$router.push({
    43. path: '/account/asset/account/search/assetDetail',
    44. query: Object.assign({}, {
    45. assetTypeId: 1037 ,
    46. assetTypeName: params.name
    47. }
    48. )
    49. })
    50. })
    51. },
    52. }

    this.$echarts是全局定义的,都差不多

    main.js

    1. import * as echarts from 'echarts'
    2. Vue.prototype.$echarts = echarts

    2. 的一句代码解析

    for (let i = 0; i < reoption.series[0].data = res.map(item => Object.assign({}, {value: item.count, name: item.asset_type_name}))

    非简写

    for (let i = 0; i < res.length; i++) {
      let item = res[i];
      let newItem = {value: item.count, name: item.asset_type_name};
      option.series[0].data.push(newItem);
    }

  • 相关阅读:
    iOS代码混淆-从入门到放弃
    linux进程间通讯--信号量
    关于js中 0 == ‘ ‘ 为 true 的问题
    算法学习笔记(19): 树上启发式合并(DSU on tree)
    多线程学习------07锁的优化及注意事项
    Netty(二)- NIO三大组件之Buffer
    Google 向中国开发者开放数百份 TensorFlow 资源
    pandas索引函数loc和iloc的区别
    在 macOS 上安装 Docker
    HTTP Mime-Type对照表
  • 原文地址:https://blog.csdn.net/m0_74608954/article/details/134518523