Considering the Apache Echart library and this example : https://echarts.apache.org/examples/en/editor.html?c=heatmap-cartesian
If I add the following code snippet :
myChart.on('click', function (params) {
myChart.dispatchAction({
type: 'highlight',
seriesIndex: [0],
});
});
It allows the user to click on a data of the heatmap and it will hightlight all data.
The hightlight action (https://echarts.apache.org/en/api.html#action) can be used with seriesIndex, seriesId and seriesName. However, heatmap are built with only one serie of data.
How could I proceed to hightlight only one line (or one value of X, or one day of the week-end) when I click on a value belonging to this line ?
For exemple, how can I highlight all data for ‘Monday’ if I click a data associated with ‘Monday’.
I have been trying to play around and :
- working with multiple series instead of one breaks the heatmap behavior.
- I can get more details about where I click with the params variable of the event listener. I could find an algorythm that focus only data of the line I focus on, but anyway the dispatchAction ‘highlight’ works only for the whole serie.
TLDR : With Apache Echart and the heatmap type of plot, how can I use highlight action toward a single value of X (or heatmap line) ?
2
Answers
Here is a code snippet that highlights a line of the heatmap and that also downplay (opposite of highlight) an hypothetical previously clicked line :
Then another code snippet that's downplay any highlighted line if you click somewhere out of heatmap (but on plot zone of course) :
You can select specific items from the series by setting the
dataIndex
in the call action object,see the the api docs for
action.highlight
.The
dataIndex
of the clicked item may be retrieved fromparams.dataIndex
, whereparams
is the argument in the
click
handler you defined; also useful are the correspondingx
andy
components, from
params.data
([x, y] = params.data
).The
dataIndex
is simply the index of the item’s data in the seriesdata
array;params.seriesIndex
may be used to identify the series, especially if there is more than one.An example handler that selects a line, that is all the items with the same
y
value as the clicked item, (the same day of the week):Snippet: