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

效果

相关推荐
javaの历练之路3 天前
基于 SpringBoot+Vue2 的前后端分离博客管理系统(含 WebSocket+ECharts)
spring boot·websocket·echarts
黑幕困兽4 天前
ehcarts 实现 饼图扇区间隙+透明外描边
前端·echarts
安卓理事人5 天前
安卓多种通知ui更新的方式(livedata,rxjava,eventbus等)
android·ui·echarts
Danny_FD6 天前
用 ECharts markLine 标注节假日
前端·echarts
java水泥工7 天前
基于Echarts+HTML5可视化数据大屏展示-物流大数据展示
大数据·前端·echarts·html5·可视化大屏
Danny_FD7 天前
使用 ECharts + ECharts-GL 生成 3D 环形图
前端·echarts
我是ed7 天前
# vue3 使用 echarts 展示某省份各区市数据
前端·echarts
Danny_FD8 天前
使用Highcharts创建3D环形图
前端·echarts
fruge11 天前
前端可视化家庭账单:用 ECharts 实现支出统计与趋势分析
前端·javascript·echarts
菥菥爱嘻嘻12 天前
React + ECharts 实践:构建可交互的数据可视化组件
react.js·信息可视化·echarts