#Echarts:热力图 type: “heatmap“图例显示

html

html 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Heatmap on Cartesian - Apache ECharts Demo</title>
  <link rel="stylesheet" href="./style.css">
</head>
<body>
  <div id="chart-container"></div>
  <script src="https://registry.npmmirror.com/echarts/5.4.3/files/dist/echarts.min.js"></script>
  <script src="./index.js"></script>
</body>
</html>

js

javascript 复制代码
var dom = document.getElementById("chart-container");
var myChart = echarts.init(dom, null, {
  renderer: "canvas",
  useDirtyRect: false,
});
var app = {};

var option;

// prettier-ignore
const hours = [
    '10:28', '10:29', '11:29', '12:29'
];
// prettier-ignore
const data = [
  {
    name: '111',
    value: [0, 2, 10], // 转换为数值类型
    groupId: hours[0],
  },
  {
    name: '222',
    value: [1, 2, 100], // 转换为数值类型
    groupId: hours[1],
  },
  {
    name: '333',
    value: [2, 2, 10], // 转换为数值类型
    groupId: hours[2],
  }
];
option = {
  tooltip: {
    position: "top",
    formatter: (params) => {
      return `${params.data.groupId} <br> ${params.marker} ${params.name} `;
    },
  },
  grid: {
    height: "50%",
    top: "10%",
  },
  xAxis: {
    type: "category",
    data: hours,
    splitArea: {
      show: true,
    },
  },
  yAxis: {
    type: "category",
    data: ["", "", "", "", ""],
    splitArea: {
      show: true,
    },
  },
  visualMap: {
    show: true,
    type: "piecewise",
    pieces: [
      {
        value: 10,
        color: "green",
        label: "正常",
      },
      {
        value: 100,
        color: "pink",
        label: "异常",
      },
    ],
    orient: "horizontal",
    left: "center",
    bottom: "15%",
  },
  series: [
    {
      type: "heatmap",
      data: data,
      label: {
        show: true,
      },
      emphasis: {
        itemStyle: {
          shadowBlur: 10,
          shadowColor: "rgba(0, 0, 0, 0.5)",
        },
      },
      itemStyle: {
        borderWidth: 1,
        borderColor: "#fff",
      },
    },
  ],
};

if (option && typeof option === "object") {
  myChart.setOption(option);
}

window.addEventListener("resize", function () {
  myChart.resize();
});

效果

相关推荐
Ticnix20 小时前
函数封装实现Echarts多表渲染/叠加渲染
前端·echarts
小徐_23332 天前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
java水泥工2 天前
基于Echarts+HTML5可视化数据大屏展示-白茶大数据溯源平台V2
大数据·echarts·html5
码上暴富4 天前
Echarts雷达图根据数值确定颜色
前端·javascript·echarts
懒大王95274 天前
uni-app + Vue3 开发展示 echarts 图表
前端·uni-app·echarts
小谭鸡米花5 天前
uni小程序中使用Echarts图表
前端·小程序·echarts
@AfeiyuO7 天前
分类别柱状图(Vue3)
typescript·vue·echarts
Pu_Nine_97 天前
10 分钟上手 ECharts:从“能跑”到“生产级”的完整踩坑之旅
前端·javascript·echarts·css3·html5
小白_ysf7 天前
uniapp和vue3项目中引入echarts 、lime-echart(微信小程序、H5等)
微信小程序·uni-app·echarts·h5·lime-echart
Chan168 天前
【智能协同云图库】基于统一接口架构构建多维度分析功能、结合 ECharts 可视化与权限校验实现用户 / 管理员图库统计、通过 SQL 优化与流式处理提升数据
java·spring boot·后端·sql·spring·intellij-idea·echarts