plotly/plotly.js · warning

Calling _doPlot as if redrawing but this container doesn't y

Error message

Calling _doPlot as if redrawing but this container doesn't yet have a plot.

What it means

Plotly.react/Plotly.newPlot funnel into _doPlot. If neither data nor layout is passed and the graph div was never plotted (no gd._fullLayout / plot context), the call is effectively a 'redraw' of nothing, so plotly.js logs this warning and skips plotting instead of crashing.

Source

Thrown at src/plot_api/plot_api.js:81

    // Events.init is idempotent and bails early if gd has already been init'd
    Events.init(gd);

    if (Lib.isPlainObject(data)) {
        var obj = data;
        data = obj.data;
        layout = obj.layout;
        config = obj.config;
        frames = obj.frames;
    }

    var okToPlot = Events.triggerHandler(gd, 'plotly_beforeplot', [data, layout, config]);
    if (okToPlot === false) return Promise.reject();

    // if there's no data or layout, and this isn't yet a plotly plot
    // container, log a warning to help plotly.js users debug
    if (!data && !layout && !Lib.isPlotDiv(gd)) {
        Lib.warn('Calling _doPlot as if redrawing ' + "but this container doesn't yet have a plot.", gd);
    }

    function addFrames() {
        if (frames) {
            return exports.addFrames(gd, frames);
        }
    }

    // transfer configuration options to gd until we move over to
    // a more OO like model
    setPlotContext(gd, config);

    if (!layout) layout = {};

    // hook class for plots main container (in case of plotly.js
    // this won't be #embedded-graph or .js-tab-contents)
    d3.select(gd).classed('js-plotly-plot', true);

View on GitHub (pinned to 1d090e0b5f)

Solutions

  1. Call Plotly.newPlot(gd, data, layout) (or Plotly.react) first, and only redraw after its promise resolves
  2. Check the div was actually plotted, e.g. gd._fullLayout exists or Plotly.d3.select(gd).selectAll('.plotly').size() > 0, before calling redraw
  3. Ensure data and/or layout is passed when you intend to plot, since redraw only re-renders an existing plot
  4. Verify you selected the correct graph div id; a missing element silently yields an unplotted container
  5. If using React, await Plotly.newPlot before triggering state-driven redraws

Example fix

// before
const gd = document.getElementById('graph');
Plotly.redraw(gd);
// after
Plotly.newPlot(gd, data, layout).then(() => Plotly.redraw(gd));
Defensive patterns

Strategy: validation

Validate before calling

function isPlotted(gd) {
  return !!(gd && gd._fullLayout && gd._fullLayout._uid && gd.data);
}
if (!isPlotted(gd)) { await Plotly.newPlot(gd, data, layout); } else { Plotly.redraw(gd); }

Type guard

function isPlotDiv(gd) { return !!(gd && gd.classList && gd.classList.contains('js-plotly-plot')); }

Prevention

When it happens

Trigger: Plotly.redraw(gd) or Plotly.relayout/Plotly.restyle with no data/layout changes on a div where Plotly.newPlot/Plotly.react never succeeded; calling Plotly.redraw on an empty <div> or before the async newPlot promise resolved.

Common situations: Calling Plotly.redraw() inside framework lifecycle hooks (React useEffect / Angular ngAfterViewInit) before the plot exists; redraw after a failed newPlot; grabbing the wrong DOM element id so the div was never plotted; render loops triggered before async plot initialization completes.


AI-assisted analysis of plotly/plotly.js@1d090e0b5f (2026-09-02). Data as JSON: /api/errors/ba7b20ae6e773ede. Report an issue: GitHub.