echarts [Bug] Heat map: Selection does not work correctly

bejyjqdl  于 5个月前  发布在  Echarts
关注(0)|答案(2)|浏览(102)

Version

5.4.2

https://echarts.apache.org/examples/en/editor.html?code=PYBwLglsB2AEC8sDeAoWszGAG0iAXMmurCMAM4SQyEBEmItxAvgDTECG0EAth9dEIAzDtnIBTdugDmAJwgATQqhKwAFuIjS1YOgFYADAFJaUkgzoBGY03RtiADwCCDiOWXF0YAJ4hxdAGN-cWlgWW9TT1gFfg5CAG1aSwAmDlNYJLTWDNT02gBmLIyAFiLaPTKANjKAdjKADjKATjLrVstW5MZspO6cvoKB4oG9AcqBmoH6gaaB6znLRgBdM3RyEGwqJ1lxOKJVNbVgAHdCMFkAV3Eo5hYzbxc3D1UfP0Dg0PDI1RiwPcSAMr8C6yGIRHoAMXkYLyABU1CDyDCegB1cQKaDiJEccEZWFXbG42gAWRgyIyAIu0BhKyi602YG2u2eB3IR1OGEu11UtzsZgAbm4LqJiRwCPsSDwIIJYAZVrA-A5CNZ5UFsAELtgOAAjbD-TlXeVhCDiaC6DJHeQALxgf2w3xIeqE5toAVNYHEsgd6G1wDAmB4Vj0JjuxAk8ixCRUJGgHB4-toAAUqQE1LAAMIcUHejC-BMafh8bp08R6gIehSkhT6gDklGg0j1Nflv3-UXQ8TlsuyelpB1g8Us2S7lj7B3iyWHPQAtLQx6p4vkpxlZ_OSPFisvaKv5R29Fud-2B5UD3PdwOaqe1x36lfz_Emnej4Ou13t2fn5Yh93YMlrwOUmXYp_0HJcf1He9LE3cCQMsfcf3yWCTx_YDIMvH9Klg28UNgx8cPvZJX2yRCCO_LsSOfZJJx_P8CLArte3vEdshqWDsm_d8QOojjD37Rd2JnD8-OgnihPHeDRJA5DJPvdCZOfbD5L4vClPHFVYG_RjP2_b9aM_bjsj0vjLDA79MMgkTsiaWCJPYiDP2k7JzM_OSWKwgTYHqXCPJSLjmNgLS-OSHSey4gzYFYuiPKM8cu24tjf3YrjDMEkCwOozj72gjLePElKVzEhdkJywr13QkqQOwir7zw6rPzi4jYN0wzYOo-LIPSqzYOy7IvMg-DuIMJD8uc4zytCyCqomz9aumoKGoirjmtgVDKLalqosSlaQPItzIOIxqCIOgq0uOzLn2gsDzr4-CrtyoqzvusrHtKm9jvs5SXtg3aAqa47VuM6iwMiz8wNMgG1Mu9iKOM272JihdLGQsDrLQ47ArU7CwIxxG8NMoaCJ-0bx2C_6wrJzbTJ27IRISy7kpW1L7zA6DrvHaDWaevcaaS-9kM516Lx5k772wgWQLw7LvuFiHEe_DnWuFhH1xMmXurV_rhag4bGY05WO0sdDacm4W-pm4WcfXQjhZhkn5b2taba4lmmefBiNs_Htecor2RefbHDou322YXeD4JD9dkPDrmhYC12-OwgaJeDmOX192WVc073Ad9y2DYDjSCc_aCw5s32QeMqO7Ng9D4OJxHE_jtS8NLwnfdthdSbj7aCOopPNujwXOyc7O1JHv2gvHiOOzA5Dp4HaC59Tuum4e2Al6H9CN8qqfU7w7fIK7aS_vX1eVeo4rYNn0fEcXwPYfHjODeQg-XN3ofLGw1_jP3s-O2t0-Gklrj31gOKiIDnbj0wlEJYLBYHMCAA&_source=echarts-doc-preview

Steps to Reproduce

Click on a cell in the heatmap

Current Behavior

All the cells in that particular column is selected

Expected Behavior

Only the clicked cell should be selected

Environment

- OS:
- Browser:
- Framework:

Any additional comments?

No response

8tntrjer

8tntrjer1#

This issue is labeled with difficulty: easy .
@fvales Would you like to debug it by yourself? This is a quicker way to get your problem fixed. Or you may wait for the community to fix.

Please have a look at How to debug ECharts if you'd like to give a try. 🤓

mi7gmzs6

mi7gmzs62#

selectedMode is based on the name of the series. It is mainly used in 1*1 data dimensions such as legends and bar charts.

Cells with the same name on the heat map will be selected at the same time.

In order to avoid modifying the source code, you can use mouse events to listen to params and highlight the style according to the data of the selected cell.

option = {
  .....
  series: [
  {
    name: 'Punch Card',
    type: 'heatmap',
    selectedMode: false, // disable selected mode
    data: data,
    itemStyle: {
        emphasis: {
          borderColor: 'black',
          borderWidth: 2
        }
    }
}]}
var previousSelected = null;
myChart.on('click', function (params) {
  // clear previous selected
  if (previousSelected) {
    myChart.dispatchAction({
         type: 'downplay',
         seriesIndex: 0,
         dataIndex: previousSelected.dataIndex
     });
 }
  //highlight current selected
    myChart.dispatchAction({
        type: 'highlight',
        seriesIndex: 0,
        dataIndex: params.dataIndex
  });
  previousSelected = params;
});

option && myChart.setOption(option);

相关问题