【无标题】

记录一次踩坑

<template>
  <div class="more-container">
    <div ref="myChart" style="width: 1220px; height: 600px"></div>
  </div>
</template>

<script>
  import * as echarts from 'echarts'
  export default {
    name: 'More',
    components: {},
    data() {
      return {
        nodeEnv: process.env.NODE_ENV,
        myChart: null,
        selectedDataIndex: null,
        chartOption: {
          // 图表配置项
        },
      }
    },
    created() {},
    mounted() {
      this.initChart()
      this.setChartOption()
      this.bindChartEvents()
    },
    beforeDestroy() {
      if (this.myChart) {
        this.myChart.dispose()
      }
    },
    methods: {
      initChart() {
        this.myChart = echarts.init(this.$refs.myChart)
        this.chartOption = {
          title: {
            text: 'Stacked Line',
          },
          tooltip: {
            trigger: 'axis',
          },
          legend: {
            data: ['aaa', 'bbb', 'ccc', 'ddd', 'eee'],
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true,
          },
          toolbox: {
            feature: {
              saveAsImage: {},
            },
          },
          xAxis: {
            type: 'category',
            boundaryGap: false,
            data: ['1', '2', '3', '4', '5', '6', '7'],
          },
          yAxis: {
            type: 'value',
          },
          series: [
            {
              name: 'aaa',
              type: 'line',
              stack: 'Total',
              data: [120, 132, 101, 134, 90, 230, 210],
              symbolSize: 12,
              emphasis: {
                itemStyle: {
                  color: 'gray',
                },
              },
              itemStyle: {
                normal: {
                  borderWidth: 12, // 设置拐点的大小
                },
              },
            },
            {
              name: 'bbb',
              type: 'line',
              stack: 'Total',
              data: [220, 182, 191, 234, 290, 330, 310],
              symbolSize: 12,
              emphasis: {
                itemStyle: {
                  color: 'gray',
                },
              },
              itemStyle: {
                normal: {
                  borderWidth: 12, // 设置拐点的大小
                },
              },
            },
            {
              name: 'ccc',
              type: 'line',
              stack: 'Total',
              data: [150, 232, 201, 154, 190, 330, 410],
              symbolSize: 12,
              emphasis: {
                itemStyle: {
                  color: 'gray',
                },
              },
              itemStyle: {
                normal: {
                  borderWidth: 12, // 设置拐点的大小
                },
              },
            },
            {
              name: 'ddd',
              type: 'line',
              stack: 'Total',
              data: [320, 332, 301, 334, 390, 330, 320],
              symbolSize: 12,
              emphasis: {
                itemStyle: {
                  color: 'gray',
                },
              },
              itemStyle: {
                normal: {
                  borderWidth: 12, // 设置拐点的大小
                },
              },
            },
            {
              name: 'eee',
              type: 'line',
              stack: 'Total',
              data: [820, 932, 901, 934, 1290, 1330, 1320],

              symbolSize: 12,
              emphasis: {
                itemStyle: {
                  color: 'gray',
                },
              },
              itemStyle: {
                normal: {
                  borderWidth: 12, // 设置拐点的大小
                  fontSize: 12,
                },
              },
            },
          ],
        }
        this.myChart.setOption(this.chartOption)
      },
      setChartOption() {},
      bindChartEvents() {
        this.myChart.on('click', this.handleChartClick)
      },
      handleChartClick(params) {
        // 遍历所有的系列
        for (let i = 0; i < this.chartOption.series.length; i++) {
          // 获取当前系列
          let series = this.chartOption.series[i]
          // 更新数据
          series.data[params.dataIndex] = {
            value: series.data[params.dataIndex].value || series.data[params.dataIndex],
            itemStyle: {
              color: 'gray', // 设置拐点的填充颜色
              borderColor: 'gray', // 设置拐点的边框颜色
              borderWidth: 2, // 设置拐点的边框宽度
            },
          }
        }
        // 使用 setOption 方法来改变每个系列在 '4' 上的点的样式
        this.myChart.setOption(this.chartOption, true)
      },
    },
  }
</script>
<style lang="scss" scoped>
  .more-container {
    ::v-deep {
    }
  }
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值