Echarts - 多个页面内有N个 echarts 图表,封装组件 CommonEcharts 快捷实现

news2024/9/23 15:30:26

目录

  • 子组件
  • 父组件使用
    • 注意
  • option 文件
  • 效果展示
  • 相关数据处理(代码备份 - 可不看)
    • 数据处理后页面展示

子组件

CommonEcharts.vue

<template>
  <div>
    <div v-for="id in domId" :id="id" :key="id" class="echarts" />
  </div>
</template>

<script>
export default {
  name: 'CommonEcharts',
  components: {},

  props: {
    info: {
      type: Object,
      required: true
    },
    domId: {
      type: Array,
      required: true
    },
    optionsObj: {
      type: Object,
      required: true
    }
  },

  data() {
    return {
      EchartsObj: {}
    }
  },

  computed: {},

  watch: {
    info() {
      this.init()
    }
  },

  mounted() {
    window.addEventListener('resize', () => {
      this.domId.forEach((id) => {
        if (document.getElementById(id)) {
          this.EchartsObj[id] = this.$echarts.init(document.getElementById(id))
          this.EchartsObj[id].resize()
        }
      })
    })

    this.init()
  },

  created() {},

  methods: {
    init() {
      this.domId.forEach((id) => {
        if (this.EchartsObj[id]) {
          this.EchartsObj[id].dispose()
        }
        const dom = document.getElementById(id)
        if (!dom) return
        this.EchartsObj[id] = this.$echarts.init(dom)
        this.EchartsObj[id].setOption(this.optionsObj[id])
      })
    }
  }
}
</script>

<style lang='scss' scoped>
.echarts {
  height: 400px;
}
</style>

父组件使用

<template>
  <CommonEcharts :info="info" :dom-id="domId" :options-obj="optionsObj" />
</template>

<script>
import { lineEcharts, scatterEcharts, barEcharts } from './echarts-options'
import CommonEcharts from './CommonEcharts.vue'

export default {
  name: 'JdcTimeEcharts',
  components: {
    CommonEcharts
  },

  props: {
    info: {
      type: Object,
      required: true
    }
  },

  data() {
    return {
      domId: ['JdcTimeEcharts1', 'JdcTimeEcharts2', 'JdcTimeEcharts3']
    }
  },

  computed: {
    optionsObj() {
      return {
        JdcTimeEcharts1: lineEcharts(),
        JdcTimeEcharts2: scatterEcharts(),
        JdcTimeEcharts3: barEcharts()
      }
    }
  }
}
</script>

<style lang='scss' scoped>
</style>

注意

  • domId 中数据 要与 optionsObj 中数据一一对应

option 文件

echarts-options.js

import * as Echarts from 'echarts'

// 折线图 - 参考示例 https://www.makeapie.cn/echarts_content/xS9Oh_JY06.html
export function lineEcharts() {
  return {
    backgroundColor: '#080b30',
    title: {
      text: '多线图',
      textStyle: {
        align: 'center',
        color: '#fff',
        fontSize: 20
      },
      top: '5%',
      left: 'center'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        lineStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: 'rgba(0, 255, 233,0)'
              },
              {
                offset: 0.5,
                color: 'rgba(255, 255, 255,1)'
              },
              {
                offset: 1,
                color: 'rgba(0, 255, 233,0)'
              }
            ],
            global: false
          }
        }
      }
    },
    grid: {
      top: '15%',
      left: '5%',
      right: '5%',
      bottom: '15%'
      // containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        axisLine: {
          show: true
        },
        splitArea: {
          // show: true,
          color: '#f00',
          lineStyle: {
            color: '#f00'
          }
        },
        axisLabel: {
          color: '#fff'
        },
        splitLine: {
          show: false
        },
        boundaryGap: false,
        data: ['A', 'B', 'C', 'D', 'E', 'F']
      }
    ],

    yAxis: [
      {
        type: 'value',
        min: 0,
        // max: 140,
        splitNumber: 4,
        splitLine: {
          show: true,
          lineStyle: {
            color: 'rgba(255,255,255,0.1)'
          }
        },
        axisLine: {
          show: false
        },
        axisLabel: {
          show: false,
          margin: 20,
          textStyle: {
            color: '#d1e6eb'
          }
        },
        axisTick: {
          show: false
        }
      }
    ],
    series: [
      {
        name: '注册总量',
        type: 'line',
        smooth: true, // 是否平滑
        showAllSymbol: true,
        // symbol: 'image://./static/images/guang-circle.png',
        symbol: 'circle',
        symbolSize: 15,
        lineStyle: {
          normal: {
            color: '#00b3f4',
            shadowColor: 'rgba(0, 0, 0, .3)',
            shadowBlur: 0,
            shadowOffsetY: 5,
            shadowOffsetX: 5
          }
        },
        label: {
          show: true,
          position: 'top',
          textStyle: {
            color: '#00b3f4'
          }
        },
        itemStyle: {
          color: '#00b3f4',
          borderColor: '#fff',
          borderWidth: 3,
          shadowColor: 'rgba(0, 0, 0, .3)',
          shadowBlur: 0,
          shadowOffsetY: 2,
          shadowOffsetX: 2
        },
        tooltip: {
          show: false
        },
        areaStyle: {
          normal: {
            color: new Echarts.graphic.LinearGradient(
              0,
              0,
              0,
              1,
              [
                {
                  offset: 0,
                  color: 'rgba(0,179,244,0.3)'
                },
                {
                  offset: 1,
                  color: 'rgba(0,179,244,0)'
                }
              ],
              false
            ),
            shadowColor: 'rgba(0,179,244, 0.9)',
            shadowBlur: 20
          }
        },
        data: [502.84, 205.97, 332.79, 281.55, 398.35, 214.02]
      },
      {
        name: '注册总量',
        type: 'line',
        smooth: true, //是否平滑
        showAllSymbol: true,
        // symbol: 'image://./static/images/guang-circle.png',
        symbol: 'circle',
        symbolSize: 15,
        lineStyle: {
          normal: {
            color: '#00ca95',
            shadowColor: 'rgba(0, 0, 0, .3)',
            shadowBlur: 0,
            shadowOffsetY: 5,
            shadowOffsetX: 5
          }
        },
        label: {
          show: true,
          position: 'top',
          textStyle: {
            color: '#00ca95'
          }
        },

        itemStyle: {
          color: '#00ca95',
          borderColor: '#fff',
          borderWidth: 3,
          shadowColor: 'rgba(0, 0, 0, .3)',
          shadowBlur: 0,
          shadowOffsetY: 2,
          shadowOffsetX: 2
        },
        tooltip: {
          show: false
        },
        areaStyle: {
          normal: {
            color: new Echarts.graphic.LinearGradient(
              0,
              0,
              0,
              1,
              [
                {
                  offset: 0,
                  color: 'rgba(0,202,149,0.3)'
                },
                {
                  offset: 1,
                  color: 'rgba(0,202,149,0)'
                }
              ],
              false
            ),
            shadowColor: 'rgba(0,202,149, 0.9)',
            shadowBlur: 20
          }
        },
        data: [281.55, 398.35, 214.02, 179.55, 289.57, 356.14]
      }
    ]
  }
}
// 散点图 - 参考示例 https://www.makeapie.cn/echarts_content/xZvv5T7_R6.html
export function scatterEcharts() {
  return {
    tooltip: {
      position: 'top'
    },
    legend: {
      left: 'center'
    },
    title: [],
    xAxis: {
      name: '公开年份',
      nameLocation: 'center',
      nameGap: 30,
      type: 'category',
      data: ['2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021'],
      boundaryGap: false,
      splitLine: {
        show: false
      },
      axisLine: {
        show: false
      }
    },
    yAxis: {
      name: 'IPC分类号',
      nameLocation: 'center',
      nameGap: 50,
      type: 'category',
      data: ['G06F', 'G06Q', 'G10L', 'G06K', 'H04L', 'G16H', 'G05B', 'G08C', 'H04N', 'H04M'],
      axisLabel: {
        margin: 20
      },
      splitLine: {
        show: true,
        lineStyle: {
          type: 'dashed'
        }
      },
      axisLine: {
        show: false
      }
    },
    series: [
      {
        name: 'G06F',
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        data: [
          [0, 0, 444],
          [1, 0, 699],
          [2, 0, 951],
          [3, 0, 1126],
          [4, 0, 1347],
          [5, 0, 1993],
          [6, 0, 3096],
          [7, 0, 5196],
          [8, 0, 1750],
          [9, 0, 222]
        ],
        animationDelay: (idx) => {
          return idx * 5
        }
      },
      {
        name: 'G06Q',
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        data: [
          [0, 1, 484],
          [1, 1, 239],
          [2, 1, 351],
          [3, 1, 126],
          [4, 1, 347],
          [5, 1, 993],
          [6, 1, 2096],
          [7, 1, 5196],
          [8, 1, 1750],
          [9, 1, 222]
        ],
        animationDelay: (idx) => {
          return idx * 5
        }
      },
      {
        name: 'G10L',
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        data: [
          [0, 2, 44],
          [1, 2, 69],
          [2, 2, 1951],
          [3, 2, 116],
          [4, 2, 147],
          [5, 2, 993],
          [6, 2, 3096],
          [7, 2, 596],
          [8, 0, 1750],
          [9, 2, 222]
        ],
        animationDelay: (idx) => {
          return idx * 5
        }
      },
      {
        name: 'G06K',
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        data: [
          [0, 3, 1444],
          [1, 3, 1699],
          [2, 3, 1951],
          [3, 3, 1126],
          [4, 3, 147],
          [5, 3, 1993],
          [6, 3, 396],
          [7, 3, 5196],
          [8, 3, 150],
          [9, 3, 2212]
        ],
        animationDelay: (idx) => {
          return idx * 5
        }
      },
      {
        name: 'H04L',
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        data: [
          [0, 4, 444],
          [1, 4, 699],
          [2, 4, 951],
          [3, 4, 1126],
          [4, 4, 1347],
          [5, 4, 1993],
          [6, 4, 3096],
          [7, 4, 5196],
          [8, 4, 1750],
          [9, 4, 222]
        ],
        animationDelay: (idx) => {
          return idx * 5
        }
      },
      {
        name: 'G16H',
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        data: [
          [0, 5, 444],
          [1, 5, 699],
          [2, 5, 951],
          [3, 5, 1126],
          [4, 5, 1347],
          [5, 5, 1993],
          [6, 5, 3096],
          [7, 5, 5196],
          [8, 5, 1750],
          [9, 5, 222]
        ],
        animationDelay: (idx) => {
          return idx * 5
        }
      },
      {
        name: 'G05B',
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        data: [
          [0, 6, 444],
          [1, 6, 699],
          [2, 6, 951],
          [3, 6, 1126],
          [4, 6, 1347],
          [5, 6, 1993],
          [6, 6, 3096],
          [7, 6, 5196],
          [8, 6, 1750],
          [9, 6, 222]
        ],
        animationDelay: (idx) => {
          return idx * 5
        }
      },
      {
        name: 'G08C',
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        data: [
          [0, 7, 444],
          [1, 7, 699],
          [2, 7, 951],
          [3, 7, 1126],
          [4, 7, 1347],
          [5, 7, 1993],
          [6, 7, 3096],
          [7, 7, 5196],
          [8, 7, 1750],
          [9, 7, 222]
        ],
        animationDelay: (idx) => {
          return idx * 5
        }
      },
      {
        name: 'H04N',
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        data: [
          [0, 8, 444],
          [1, 8, 699],
          [2, 8, 951],
          [3, 8, 1126],
          [4, 8, 1347],
          [5, 8, 1993],
          [6, 8, 3096],
          [7, 8, 5196],
          [8, 8, 1750],
          [9, 8, 222]
        ],
        animationDelay: (idx) => {
          return idx * 5
        }
      },
      {
        name: 'H04M',
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        data: [
          [0, 9, 444],
          [1, 9, 699],
          [2, 9, 951],
          [3, 9, 1126],
          [4, 9, 1347],
          [5, 9, 1993],
          [6, 9, 3096],
          [7, 9, 5196],
          [8, 9, 1750],
          [9, 9, 222]
        ],
        animationDelay: (idx) => {
          return idx * 5
        }
      }
    ]
  }
}
// 柱状图 - 参考示例 https://www.makeapie.cn/echarts_content/xQWEnqAtdc.html
export function barEcharts() {
  return {
    backgroundColor: '#001120',
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        // 坐标轴指示器,坐标轴触发有效
        type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
      }
    },
    legend: {
      data: ['邮件营销', '联盟广告'],
      textStyle: {
        color: 'rgba(55,255,249,1)'
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
        splitLine: {
          show: false
        },
        axisLine: {
          lineStyle: {
            color: 'rgba(55,255,249,1)'
          }
        },
        axisLabel: {
          color: 'rgba(55,255,249,1)'
        }
      }
    ],
    yAxis: [
      {
        type: 'value',
        splitLine: {
          show: false
        },
        axisLine: {
          lineStyle: {
            color: 'rgba(55,255,249,1)'
          }
        }
      }
    ],
    series: [
      {
        name: '邮件营销',
        type: 'bar',
        barWidth: 20,
        itemStyle: {
          barBorderRadius: 20,
          color: new Echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0,
              color: 'rgba(55,255,249,1)'
            },
            {
              offset: 1,
              color: 'rgba(0,222,215,0.2)'
            }
          ])
        },
        data: [120, 132, 101, 134, 90, 230, 210]
      },
      {
        // 替代柱状图 默认不显示颜色,是最下方柱图(邮件营销)的value值 - 20
        type: 'bar',
        barWidth: 20,
        barGap: '-100%',
        stack: '广告',
        itemStyle: {
          color: 'transparent'
        },
        data: [100, 102, 81, 114, 70, 210, 190]
      },
      {
        name: '联盟广告',
        type: 'bar',
        barWidth: 20,
        barGap: '-100%',
        stack: '广告',
        itemStyle: {
          barBorderRadius: 20,
          color: new Echarts.graphic.LinearGradient(0, 0, 0, 1, [
            {
              offset: 0.4,
              color: 'rgba(255,252,0,1)'
            },
            {
              offset: 1,
              color: 'rgba(8,228,222,0.2)'
            }
          ])
        },
        data: [220, 182, 191, 234, 290, 330, 310]
      }
    ]
  }
}

效果展示

在这里插入图片描述

相关数据处理(代码备份 - 可不看)

/**** echarts 折线图、散点图 - 数据处理 ****/

// 数据源
const info = {
  itemMap: {
    警告: [
      {
        total: 28,
        cfzl: '1',
        cfzlView: '警告',
        wfxl: '12',
        wfxlView: '超速行驶',
        jtfs: 'B11',
        jtfsView: '重型栏板半挂车'
      },
      {
        total: 3,
        cfzl: '1',
        cfzlView: '警告',
        wfxl: '17',
        wfxlView: '未低速通过',
        jtfs: 'B11',
        jtfsView: '重型栏板半挂车'
      },
      {
        total: 6,
        cfzl: '1',
        cfzlView: '警告',
        wfxl: '26',
        wfxlView: '违法停车',
        jtfs: 'B11',
        jtfsView: '重型栏板半挂车'
      },
      {
        total: 21,
        cfzl: '1',
        cfzlView: '警告',
        wfxl: '28',
        wfxlView: '违法装载',
        jtfs: 'B11',
        jtfsView: '重型栏板半挂车'
      },
      {
        total: 3,
        cfzl: '1',
        cfzlView: '警告',
        wfxl: '49',
        wfxlView: '其他影响安全行为',
        jtfs: 'B11',
        jtfsView: '重型栏板半挂车'
      },
      {
        total: 1,
        cfzl: '1',
        cfzlView: '警告',
        wfxl: '28',
        wfxlView: '违法装载',
        jtfs: 'B21',
        jtfsView: '中型栏板半挂车'
      }
    ],
    罚款: [
      {
        total: 56,
        cfzl: '2',
        cfzlView: '罚款',
        wfxl: '12',
        wfxlView: '超速行驶',
        jtfs: 'B11',
        jtfsView: '重型栏板半挂车'
      },
      {
        total: 6,
        cfzl: '2',
        cfzlView: '罚款',
        wfxl: '17',
        wfxlView: '未低速通过',
        jtfs: 'B11',
        jtfsView: '重型栏板半挂车'
      },
      {
        total: 12,
        cfzl: '2',
        cfzlView: '罚款',
        wfxl: '26',
        wfxlView: '违法停车',
        jtfs: 'B11',
        jtfsView: '重型栏板半挂车'
      },
      {
        total: 42,
        cfzl: '2',
        cfzlView: '罚款',
        wfxl: '28',
        wfxlView: '违法装载',
        jtfs: 'B11',
        jtfsView: '重型栏板半挂车'
      },
      {
        total: 6,
        cfzl: '2',
        cfzlView: '罚款',
        wfxl: '49',
        wfxlView: '其他影响安全行为',
        jtfs: 'B11',
        jtfsView: '重型栏板半挂车'
      },
      {
        total: 2,
        cfzl: '2',
        cfzlView: '罚款',
        wfxl: '28',
        wfxlView: '违法装载',
        jtfs: 'B21',
        jtfsView: '中型栏板半挂车'
      }
    ]
  },
  columns: [
    { jtfs: 'B11', jtfsView: '重型栏板半挂车' },
    { jtfs: 'B21', jtfsView: '中型栏板半挂车' }
  ]
}

// 处理代码
function optionsObj() {
  const xAxisData = []
  const yAxisData = []
  this.info?.columns?.forEach((item) => {
    !xAxisData.includes(item.jtfsView) && xAxisData.push(item.jtfsView)
  })
  const seriesNameList = Object.keys(this.info?.itemMap)
  const seriesList1 = []
  const seriesList2 = []
  seriesNameList.forEach((seriesName) => {
    const data1 = []

    this.info?.itemMap[seriesName].forEach((i) => {
      const xIndex = xAxisData.findIndex((xItem) => xItem === i.jtfsView)
      const yIndex = yAxisData.findIndex((yItem) => yItem === i.wfxlView)
      if (!yAxisData.includes(i.wfxlView)) {
        yAxisData.push(i.wfxlView)
        seriesList2.push({
          name: i.wfxlView,
          data: [[xIndex, seriesList2.length, i.total]]
        })
      } else {
        const seriesList2Index = seriesList2.findIndex(
          (seriesList2Item) => seriesList2Item.name === i.wfxlView
        )
        const seriesDataIndex = seriesList2[seriesList2Index].data.findIndex(
          (dataItem) => dataItem[0] === xIndex && dataItem[1] === yIndex
        )
        if (seriesDataIndex !== -1) {
          seriesList2[seriesList2Index].data[seriesDataIndex] = [
            xIndex,
            yIndex,
            i.total + seriesList2[seriesList2Index].data[seriesDataIndex][2]
          ]
        } else {
          seriesList2[seriesList2Index].data.push([xIndex, yIndex, i.total])
        }
      }
      data1[xIndex] = (data1[xIndex] || 0) + (i.total || 0)
    })
    seriesList1.push({
      name: seriesName,
      data: data1
    })
  })

  console.log('xAxisData----', xAxisData)
  console.log('yAxisData----', yAxisData)
  console.log('seriesList1----', seriesList1)
  console.log('seriesList2----', seriesList2)

  return {
    // 折线图
    JdcTimeEcharts1: lineEcharts({
      xAxisData,
      seriesList: seriesList1
    }),
    // 散点图
    JdcTimeEcharts2: scatterEcharts({
      xAxisName: '车辆类型',
      xAxisData,
      yAxisData,
      seriesList: seriesList2
    })
  }
}

// 处理结果
const xAxisData = ['重型栏板半挂车', '中型栏板半挂车']
const yAxisData = ['超速行驶', '未低速通过', '违法停车', '违法装载', '其他影响安全行为']
const seriesList1 = [
  {
    name: '警告',
    data: [61, 1]
  },
  {
    name: '罚款',
    data: [122, 2]
  }
]
const seriesList2 = [
  {
    name: '超速行驶',
    data: [[0, 0, 84]]
  },
  {
    name: '未低速通过',
    data: [[0, 1, 9]]
  },
  {
    name: '违法停车',
    data: [[0, 2, 18]]
  },
  {
    name: '违法装载',
    data: [[0, 3, 63], [1, 3, 3]]
  },
  {
    name: '其他影响安全行为',
    data: [[0, 4, 9]]
  }
]

/**** echarts图表option配置项 ****/
// import * as Echarts from 'echarts'

// 折线图
function lineEcharts({ xAxisData = [], seriesList = [] }) {
  const colorList = [
    '#00b3f4',
    '#00ca95',
    '#fce07e',
    '#f18585',
    '#8fcde5',
    '#62b58e',
    '#fd9d75',
    '#ae80c3'
  ]
  const defaultColor = '#ee96d6'

  return {
    backgroundColor: '#080b30',
    title: {
      show: !xAxisData.length && !seriesList.length,
      text: '暂无数据',
      left: 'center',
      top: 'center',
      textStyle: {
        color: '#fff'
      }
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        lineStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: 'rgba(0, 255, 233,0)'
              },
              {
                offset: 0.5,
                color: 'rgba(255, 255, 255,1)'
              },
              {
                offset: 1,
                color: 'rgba(0, 255, 233,0)'
              }
            ],
            global: false
          }
        }
      }
    },
    grid: {
      top: '15%',
      left: '5%',
      right: '5%',
      bottom: '15%'
      // containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        axisLine: {
          show: true
        },
        splitArea: {
          // show: true,
          color: '#f00',
          lineStyle: {
            color: '#f00'
          }
        },
        axisLabel: {
          color: '#fff'
        },
        splitLine: {
          show: false
        },
        boundaryGap: false,
        // data: ['A', 'B', 'C', 'D', 'E', 'F']
        data: xAxisData
      }
    ],

    yAxis: [
      {
        type: 'value',
        min: 0,
        // max: 140,
        splitNumber: 4,
        splitLine: {
          show: true,
          lineStyle: {
            color: 'rgba(255,255,255,0.1)'
          }
        },
        axisLine: {
          show: false
        },
        axisLabel: {
          show: false,
          margin: 20,
          textStyle: {
            color: '#d1e6eb'
          }
        },
        axisTick: {
          show: false
        }
      }
    ],
    series: seriesList.map((item, index) => {
      return {
        name: item.name,
        type: 'line',
        smooth: true,
        showAllSymbol: true,
        symbol: 'circle',
        symbolSize: 15,
        lineStyle: {
          normal: {
            color: colorList[index] || defaultColor,
            shadowColor: 'rgba(0, 0, 0, .3)',
            shadowBlur: 0,
            shadowOffsetY: 5,
            shadowOffsetX: 5
          }
        },
        label: {
          show: true,
          position: 'top',
          textStyle: {
            color: colorList[index] || defaultColor
          }
        },
        itemStyle: {
          color: colorList[index] || defaultColor,
          borderColor: '#fff',
          borderWidth: 3,
          shadowColor: 'rgba(0, 0, 0, .3)',
          shadowBlur: 0,
          shadowOffsetY: 2,
          shadowOffsetX: 2
        },
        areaStyle: {
          normal: {
            color: new Echarts.graphic.LinearGradient(
              0,
              0,
              0,
              1,
              [
                {
                  offset: 0,
                  color: (colorList[index] || defaultColor) + '4d' // 30%
                },
                {
                  offset: 1,
                  color: (colorList[index] || defaultColor) + '00' // 0%
                }
              ],
              false
            ),
            shadowColor: (colorList[index] || defaultColor) + 'e6', // 90%
            shadowBlur: 20
          }
        },
        // data: [502.84, 205.97, 332.79, 281.55, 398.35, 214.02]
        data: item.data
      }
    })
  }
}
// 散点图
function scatterEcharts({ xAxisName = '', xAxisData = [], yAxisData = [], seriesList = [] }) {
  return {
    title: {
      show: !xAxisData.length && !yAxisData.length && !seriesList.length,
      text: '暂无数据',
      left: 'center',
      top: 'center',
      textStyle: {
        color: '#fff'
      }
    },
    tooltip: {
      position: 'top',
      formatter: function(params) {
        return (
          yAxisData[params.value[1]] +
          '<br />' +
          params.marker +
          xAxisData[params.value[0]] +
          ':' +
          params.value[2]
        )
      }
    },
    legend: {
      show: false,
      left: 'center'
    },
    xAxis: {
      name: xAxisName,
      nameLocation: 'center',
      nameGap: 30,
      type: 'category',
      boundaryGap: false,
      splitLine: {
        show: false
      },
      axisLine: {
        show: false
      },
      // data: ['2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021'],
      data: xAxisData
    },
    yAxis: {
      name: '',
      nameLocation: 'center',
      nameGap: 50,
      type: 'category',
      axisLabel: {
        margin: 20
      },
      splitLine: {
        show: true,
        lineStyle: {
          type: 'dashed'
        }
      },
      axisLine: {
        show: false
      },
      // data: ['G06F', 'G06Q', 'G10L', 'G06K', 'H04L', 'G16H', 'G05B', 'G08C', 'H04N', 'H04M'],
      data: yAxisData
    },

    series: seriesList.map((item) => {
      return {
        name: item.name,
        type: 'scatter',
        symbolSize: (val) => {
          return val[2] % 40
        },
        animationDelay: (idx) => {
          return idx * 5
        },
        // data: [
        //   [0, 0, 444],
        //   [1, 0, 699],
        //   [2, 0, 951],
        //   [3, 0, 1126],
        //   [4, 0, 1347],
        //   [5, 0, 1993],
        //   [6, 0, 3096],
        //   [7, 0, 5196],
        //   [8, 0, 1750],
        //   [9, 0, 222]
        // ],
        data: item.data
      }
    })
  }
}

数据处理后页面展示

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1696022.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

springboot+vue+mybatis校园兼职平台+PPT+论文+讲解+售后

社会的发展和科学技术的进步&#xff0c;互联网技术越来越受欢迎。网络计算机的生活方式逐渐受到广大人民群众的喜爱&#xff0c;也逐渐进入了每个学生的使用。互联网具有便利性&#xff0c;速度快&#xff0c;效率高&#xff0c;成本低等优点。 因此&#xff0c;构建符合自己要…

十、通配符和正则表达式

10.1 通配符 通配符是由shell处理的, 它只会出现在 命令的“参数”里。当shell在“参数”中遇到了通配符 时&#xff0c;shell会将其当作路径或文件名去在磁盘上搜寻可能的匹配&#xff1a;若符合要求的匹配存在&#xff0c;则进 行代换(路径扩展)&#xff1b;否则就将该通配…

基于springboot+vue的致远汽车租赁系统

开发语言&#xff1a;Java框架&#xff1a;springbootJDK版本&#xff1a;JDK1.8服务器&#xff1a;tomcat7数据库&#xff1a;mysql 5.7&#xff08;一定要5.7版本&#xff09;数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/ideaMaven包&#xff1a;…

新兴勒索软件组织不断涌现:他们是谁,如何运作

新兴的勒索软件团伙正采取不同的策略和目标&#xff0c;填补大公司关闭和执法中断所留下的空白。 3 月份 BlackCat (ALPHV) 的关闭和 2 月份执法部门对 LockBit 基础设施的干扰导致勒索软件生态系统出现空白&#xff0c;而这一空白正迅速被经验不足的团体所填补。 今年到目前…

Flask实现文件上传/下载【基础版】

目录 前言 一.文件上传 1.1一些<input>相关上传属性 1.1.1multiple 1.1.2accept 1.2Flask后台接收文件提交 1.3Flask后台接收多个文件 二.保护文件上传 2.1限制文件上传大小 2.2验证文件名 2.3验证文件内容 三.文件下载 3.1使用send_file()方法下载文件 前言…

SwiftUI中的Stepper(系统Stepper以及自定义Stepper)

本篇文章主要介绍一下Stepper&#xff0c;这个组件在UIKit中也已经有较长的历史了&#xff0c;下面看看在SwiftUI中如何使用&#xff0c;有哪些更加便捷的方法呢&#xff1f; Stepper减号(-)和加号()按钮&#xff0c;可以点击后以指定的数值进行加减。 基础初始化方法 Stepp…

【SpringCloud】服务注册与发现

目录 Eureka/注册中心简介模式 使用Eureka实现注册中心1.创建一个名称为demo-eureka-server的Spring Boot项目2.添加项目依赖3. 在启动类添加启动注解4.添加配置信息Eureka的自我保护机制为Eureka Server添加用户认证1.添加依赖2. 添加配置信息3.添加放行代码4.启动服务&#x…

NASA数据集——阿尔法喷气式大气实验甲醛(HCHO)数据

Alpha Jet Atmospheric eXperiment Formaldehyde Data 简介 阿尔法喷气式大气实验甲醛数据 阿尔法喷气式大气实验&#xff08;AJAX&#xff09;是美国国家航空航天局艾姆斯研究中心与 H211, L.L.C. 公司的合作项目&#xff0c;旨在促进对加利福尼亚、内华达和太平洋沿岸地区的…

春秋云境CVE-2018-7422

简介 WordPress Plugin Site Editor LFI 正文 1.进入靶场 2.漏洞利用 /wp-content/plugins/site-editor/editor/extensions/pagebuilder/includes/ajax_shortcode_pattern.php?ajax_path/../../../../../../flag看别人wp做的。不懂怎么弄的&#xff0c;有没有大佬讲一下的

谈谈你对 vue 的理解 ?

1.谈谈你对 vue 的理解 ? 官方: Vue是一套用于构建用户界面的渐进式框架,Vue 的核心库只关注视图层 2. 声明式框架 Vue 的核心特点,用起来简单。那我们就有必要知道命令式和声明式的区别! 早在 JQ 的时代编写的代码都是命令式的,命令式框架重要特点就是关注过程 声明…

【Chrono Engine学习总结】6-创建自定义场景-6.1-3D场景获取

由于Chrono的官方教程在一些细节方面解释的并不清楚&#xff0c;自己做了一些尝试&#xff0c;做学习总结。 Chrono可以导入自定义的三维模型&#xff0c;所以想自己搭建一个3D仿真环境。过程中遇到了一些问题&#xff0c;记录与整理。 1、3D环境的创建方法 Chrono的Irrlich…

如何从头搭建一个自己的java库并上传到maven官方仓库

创建代码 在代码库根目录执行maven命令&#xff0c;用于快速生成一个基础的Maven项目 mvn archetype:generate \-DgroupIdcom.mycompany \-DartifactIdmy-maven-project \-Dversion1.0.0 \-DarchetypeArtifactIdmaven-archetype-quickstart \-DinteractiveModefalse 这个命令…

初学Echart

创建一个html文件 1.引入 点击链接----快速上手网址&#xff1a;快速上手 - 使用手册 - Apache ECharts 复制这一串【这个是引入echart路径】 引入到这里 2.使用 我们在上一步---点击返回--往下翻---找到完整代码--复制黏贴 复制粘贴后--总体长这样 <!DOCTYPE html> &…

【YOLOv10训练教程】如何使用YOLOv10训练自己的数据集并且推理使用

《博主简介》 小伙伴们好&#xff0c;我是阿旭。专注于人工智能、AIGC、python、计算机视觉相关分享研究。 ✌更多学习资源&#xff0c;可关注公-仲-hao:【阿旭算法与机器学习】&#xff0c;共同学习交流~ &#x1f44d;感谢小伙伴们点赞、关注&#xff01; 《------往期经典推…

Oracle Graph 入门 - RDF 知识图谱

Oracle Graph 入门 - RDF 知识图谱 0. 引言1. 查看 RDF Semantic Graph 安装情况2. 创建一个语义网络4. 创建一个模型5. 加载 RDF 文件6. 配置 W3C 标准的 SPARQL 端点 0. 引言 Oracle Graph 的中文资料太少了&#xff0c;只能自己参考英文资料整理一篇吧。 Oracle 数据库包括…

【学习笔记】计算机组成原理(八)

CPU 的结构和功能 文章目录 CPU 的结构和功能8.1 CPU的结构8.1.1 CPU的功能8.1.2 CPU结构框图8.1.3 CPU的寄存器8.1.4 控制单元CU和中断系统 8.2 指令周期8.2.1 指令周期的基本概念8.2.2 指令周期的数据流 8.3 指令流水8.3.1 指令流水原理8.3.2 影响流水线性能的因素8.3.3 流水…

从0开始带你成为Kafka消息中间件高手---第二讲

从0开始带你成为Kafka消息中间件高手—第二讲 那么在消费数据的时候&#xff0c;需要从磁盘文件里读取数据后通过网络发送出去&#xff0c;这个时候怎么提升性能呢&#xff1f; 首先就是利用了page cache技术&#xff0c;之前说过&#xff0c;kafka写入数据到磁盘文件的时候&…

深入探索:中文字符的编码与转移字符的奥秘

新书上架~&#x1f447;全国包邮奥~ python实用小工具开发教程http://pythontoolsteach.com/3 欢迎关注我&#x1f446;&#xff0c;收藏下次不迷路┗|&#xff40;O′|┛ 嗷~~ 目录 一、引言&#xff1a;探索字符编码的世界 二、字符编码基础&#xff1a;理解ASCII与Unicode…

面向未来AI算力中心的电能消耗及优化策略

AI苏妲己&#xff1a;面向未来AI算力中心的电能消耗及优化策略 在人工智能&#xff08;AI&#xff09;和大模型技术加速发展的今天&#xff0c;智算中心对电力需求爆发式递增。如何降低这些中心的能耗成本&#xff0c;关于电能消耗趋势、新能源发电、以及源网荷储一体化解决方…