plotly / plotly/plotly.js

Heatmaps with hovertemplate with %{text} is not working

Offen
#6,689 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug P3
Vorherrschende Sprache
JavaScript
Sterne
18.3k
Forks
2k
Ø Merge
2 T. 12 Std.
Gemergte PRs (30 T.)
28

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die bereitgestellte HTML- und JavaScript-Reproduktion mit Plotly 2.24.1 auszuführen, und vergleiche anschließend die Handhabung von hovertemplate für die scatter- und heatmap-Traces. Verfolge das Hover-Verhalten der heatmap und dessen %{text}-Datenzuordnung; als erledigt gilt die Aufgabe, wenn der bereitgestellte Text in den heatmap-Hover-Beschriftungen erscheint, ohne das Verhalten von scatter zu beeinträchtigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.