plotly / plotly/plotly.js

X-axis type lost after restyle

Offen
#7,225 0 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

If i create a bar chart with a categorical x-axis, where the x-values are strings of digits, then restyle it with new y-values, the categoricality of the x-axis is lost, and it becomes linear, as if the type had been freshly inferred from the values.

Here is a self-contained example (i'm afraid i don't have a codepen account):

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Restyle</title>
        <script src="https://cdn.plot.ly/plotly-latest.js"></script>
        <script>
            addEventListener("DOMContentLoaded", () => {
                const plot = document.getElementById("plot");

                Plotly.newPlot(plot,
                               {
                                   data: [{
                                       type: "bar",
                                       x: ["2", "5", "10", "30", "50"],
                                       y: [1, 2, 3, 4, 5]
                                   }],
                                   layout: {
                                       xaxis: {type: "category"}
                                   },
                                   config: {
                                       responsive: true
                                   }
                               });

                document.getElementById("restyle").addEventListener("click", () => {
                    Plotly.restyle(plot, {y: [[5, 4, 3, 2, 1]]}, 0);
                });
            });
        </script>
    </head>
    <body>
        <div id="plot"></div>
        <button id="restyle">Restyle</button>
    </body>
</html>

When the page loads, the x-axis is correctly categorical, but when you click the button, it becomes incorrectly linear.

I believe this is the same problem as described in the forum post "X-axis “category” type not honored after Plotly.restyle".

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, das eigenständige HTML-Beispiel mit Plotly.newPlot und Plotly.restyle auszuführen, und verfolge anschließend den Restyle-Pfad, der das Balkendiagramm aktualisiert. Die Aufgabe ist abgeschlossen, wenn die x-Achse kategorisch bleibt, nachdem die y-Werte ersetzt wurden, statt erneut als linear inferiert zu werden.

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.