#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();
});

效果

相关推荐
吴声子夜歌2 天前
RxJava——操作符详解(四)
android·echarts·rxjava
new出一个对象5 天前
vue使用echarts实现只显示一根线的图表
前端·vue.js·echarts
KeroroLX6 天前
uniapp项目中使用echarts
javascript·uni-app·echarts
那些免费的砖6 天前
Uni ECharts - 基于 ECharts 开发的 uni-app 跨端图表解决方案,和 Vue ECharts 用法几乎一致
vue.js·uni-app·echarts
那个村的李富贵8 天前
用MySQL玩转数据可视化
mysql·信息可视化·echarts
Yaru118 天前
伪3D地图和3D饼图实现
前端·3d·echarts
计算机学姐10 天前
基于SpringBoot的校园跑腿系统【数据可视化统计+原创精品】
java·vue.js·spring boot·后端·mysql·信息可视化·echarts
徐小夕@趣谈前端10 天前
NO-CRM 2.0正式上线,Vue3+Echarts+NestJS实现的全栈CRM系统,用AI重新定义和实现客户管理系统
前端·javascript·人工智能·开源·编辑器·echarts
艾斯特_14 天前
Echarts常用配置项及解释
前端·javascript·echarts
winfredzhang15 天前
从零构建:基于 Node.js 与 ECharts 的量化交易策略模拟系统
前端·node.js·echarts·股票·策略