plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
16.8k stars 1.85k forks source link

Heatmaps with hovertemplate with %{text} is not working #6689

Open jan119 opened 1 year ago

jan119 commented 1 year ago

The following works for scatter plot where you can see %{text} is being populated from the provided text:

<head>
    <!-- Load plotly.js into the DOM -->
    <script src='https://cdn.plot.ly/plotly-2.24.1.min.js'></script>
</head>

<body>
    <div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>
</body>
var data = [
    {
        type: 'scatter',
        mode: 'lines+markers',
        x: [1, 2, 3],
        y: [2, 4, 6],
        z: [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
        hovertemplate: '<i>Price</i>: $%{y:.2f}' +
                        '<br><b>X</b>: %{x}<br>' +
                        '<b>%{text}</b>',
        text: ["Text A", "Text B", "Text C"],
        showlegend: false
    }
];

var layout = {
    title: "Set hover text with hovertemplate",
};

Plotly.newPlot('myDiv', data, layout);
Screenshot 2023-07-27 at 2 42 53 PM

But the same doesn't work you generate a heatmap (the code is the same, except changed the type to heatmap):

var data = [
    {
        type: 'heatmap',
        mode: 'lines+markers',
        x: [1, 2, 3],
        y: [2, 4, 6],
        z: [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
        hovertemplate: '<i>Price</i>: $%{y:.2f}' +
                        '<br><b>X</b>: %{x}<br>' +
                        '<b>%{text}</b>',
        text: ["Text A", "Text B", "Text C"],
        showlegend: false
    }
];

var layout = {
    title: "Set hover text with hovertemplate",
};

Plotly.newPlot('myDiv', data, layout);
Screenshot 2023-07-27 at 2 45 52 PM

Would really appreciate some help on this.

DarshanDixit05 commented 1 year ago

Hey , i wanted to work on this issue . Can you please assign it to me ? I'll fix it asap.

anaestheramaral commented 1 year ago

It works fine for me when I use text with the same dimension and length as z