echarts折线图与散点图(共用legend,tootip不影响)

折磨了几个小时,人都麻了

需求是这样:tootip散点图显示一个点

 折线图全部展示一条线上的

思路: 通过设置tootip设置item,画两条x轴,其中一条设置触发方式type: 'line'(类似为axis)

<template>
  <div class="erter">
    <div class="etet" ref="myecharts"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      myecharts: null,
      newOption: [],
    };
  },
  mounted() {
    this.myChart = this.$echarts.init(this.$refs.myecharts);
    this.drawing();
  },
  methods: {
    drawing() {
      const option = {
        legend: {
          show: true,
          data: ["111", "222"],
        },
        xAxis: [
          {
            data: ["1", "2", "3", "4", "5", "6", "7"],
            axisPointer: {
            show: true,
            type: 'line',
            label: {
              show: false,
            },
          },

          },
          {
            data: ["1", "2", "3", "4", "5", "6", "7"],
          },
        ],
        tooltip: {
          show: true,
          trigger: "item",
        },
        yAxis: [
          {},
          {
          },
        ],
        grid: [
          {
            bottom: "60%",
          },
        ],
        series: [
          {
            type: "line",
            name: "111",
            data: [1220, 1832, 1491, 2354, 2960, 3730, 8310],
          },
          {
            type: "line",
            name: "222",
            data: [2220, 1832, 1941, 2534, 2960, 3370, 3110],
          },
          {
            type: "line",
            name: "111",
            symbol: 'circle',
            symbolSize: '7',
            data: [[3, 2960]],
            xAxisIndex: 1,
            yAxisIndex: 1,
          },
          {
            type: "line",
            name: "222",
            symbol: 'circle',
            symbolSize: '7',
            data: [[4, 2960]],
            xAxisIndex: 1,
            yAxisIndex: 1,
          },
        ],
      };

      this.myChart.setOption(option, false);
    },
  },
};
</script>

<style scoped>
.box1 {
  font-size: 12px;
}
.etet {
  height: 500px;
  width: 1200px;
}
.erter {
  height: 100%;
  width: 100%;
  background-color: antiquewhite;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要将echarts折线图散点图,你可以按照以下步骤进行修: 1. 首先,将代码示例中的option对象中的type属性从'line'为'scatter',以指定图表类型为散点图。 修后的代码示例如下: ``` series: \[ { name:'曲线1', symbolSize: 5, data: \[ \[0, 2\], \[2, 5\], \[3, 9\], \[5, 16\], \[7, 24\], \[9, 18\], \[12, 15\], \[15, 5\], \[17, 2\], \[19, 1\] \], type: 'scatter', smooth: true, showSymbol: false, barGap: 0 }, { name:'曲线2', symbolSize: 5, data: \[ \[0, 1\], \[2, 3\], \[3, 7\], \[5, 13\], \[7, 21\], \[9, 16\], \[12, 12\], \[15, 3\], \[17, 1\], \[19, 0\] \], type: 'scatter', smooth: true, showSymbol: false, barGap: 0 } \] ``` 2. 然后,根据你的需求,可以进一步调整散点图的其他配置项,比如symbolSize属性可以调整散点的大小,smooth属性可以控制是否平滑显示散点图等。 完成以上修后,你的echarts折线图就成功成了散点图。 #### 引用[.reference_title] - *1* *3* [echarts图表-饼图、柱状图、折线图散点图之间相互切换](https://blog.csdn.net/m0_72603435/article/details/127970766)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [echarts-散点图数值对实现折线图](https://blog.csdn.net/fightingcoder419/article/details/79817562)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天气晚来秋~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值