Echarts自定义tooltip悬浮提示框

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>ECharts Line Chart Demo</title>
  <!-- ECharts script -->
  <script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
  <style>
    #main {
      width: 600px;
      height: 400px;
    }
  </style>
</head>

<body>
  <div id="main"></div>

  <script>
    // Initialize the chart
    var myChart = echarts.init(document.getElementById('main'))

    // Specify the chart options
    var option = {
      title: {
        text: 'Smooth Line Chart with Colored Segments'
      },
      tooltip: {
        trigger: 'axis',
        backgroundColor: "rgba(0,0,0,0.3)",
        textStyle: {
          show: false,
          color: "#FFFFFF", // 文字的颜色
        },
        borderColor: "rgba(0,0,0,0.3)",
        borderWidth: 1,
        formatter: function (params) {
          console.log('params', params)
          return (
            params[0].marker +
            "心率: " + params[0].data +
            "<br/><span style='margin-left:0.25rem'></span>" +
            params[0].axisValue
          )
        },
      },
      xAxis: {
        type: 'category',
        data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        axisTick: {
          show: false  // Disable x-axis tick lines
        },
        axisLine: {
          show: true,  // Enable x-axis line
          lineStyle: {
            color: '#CCCCCC',  // Set y-axis line color
          },
        },
        axisLabel: {
          color: '#000000'  // Set x-axis label color
        },
        splitLine: {
          show: true,  // Show x-axis grid lines
          lineStyle: {
            type: 'dashed'  // Set grid lines to dashed
          }
        }
      },
      yAxis: {
        type: 'value',
        axisTick: {
          show: false  // Disable y-axis tick lines
        },
        axisLabel: {
          color: '#000000'  // Set x-axis label color
        },
        axisLine: {
          show: true,  // Enable y-axis line
          lineStyle: {
            color: '#CCCCCC',  // Set y-axis line color
          },
        },
        splitLine: {
          show: true,  // Show y-axis grid lines
          lineStyle: {
            type: 'dashed'  // Set grid lines to dashed
          }
        }
      },
      series: [
        {
          name: 'Values',
          type: 'line',
          smooth: true,
          data: [12, 18, 23, 28, 34, 26, 19, 14, 22, 30, 32, 27],
          showSymbol: false  // Disable the points at each data mark
        }
      ],
      visualMap: {
        show: false,
        dimension: 1,
        pieces: [
          {
            gt: 10,
            lte: 20,
            color: 'red'
          },
          {
            gt: 20,
            lte: 30,
            color: 'blue'
          },
          {
            gt: 30,
            lte: 40,
            color: 'green'
          }
        ]
      }
    }

    // Set the chart options
    myChart.setOption(option)
  </script>
</body>

</html>
  • 19
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

萧寂173

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

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

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

打赏作者

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

抵扣说明:

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

余额充值