OpenBB-finance/OpenBB · error · RuntimeError

Failed to automatically create a generic chart with the data

Error message

Failed to automatically create a generic chart with the data provided.

What it means

The sibling auto-chart fallback in Charting.to_chart: after the specific chart path fails, it tries create_line_chart on the converted DataFrame; if that also raises, the exception is chained into this RuntimeError. The underlying exception is available via __cause__ (unlike error 170 it is not embedded in the message), so 'raise ... from e' preserves the real reason.

Source

Thrown at openbb_platform/obbject_extensions/charting/openbb_charting/charting.py:658

        kwargs["provider"] = self._obbject.provider  # pylint: disable=protected-access
        kwargs["extra"] = self._obbject.extra  # pylint: disable=protected-access
        try:
            if has_data:
                self.show(data=data_as_df, render=render, **kwargs)
            else:
                self.show(**kwargs, render=render)
        except Exception:  # pylint: disable=W0718
            try:
                fig = self.create_line_chart(data=data_as_df, render=False, **kwargs)
                fig = self._set_chart_style(fig)  # type: ignore
                content = fig.show(external=True, **kwargs).to_plotly_json()  # type: ignore
                self._obbject.chart = Chart(
                    fig=fig, content=content, format=self._format
                )
                if render:
                    return fig.show(**kwargs)  # type: ignore
            except Exception as e:  # pylint: disable=W0718
                raise RuntimeError(
                    "Failed to automatically create a generic chart with the data provided."
                ) from e

    def _set_chart_style(self, figure: "Figure"):
        """Set the user preference for light or dark mode."""
        return figure

    def toggle_chart_style(self):
        """Toggle the chart style between light and dark mode."""
        import plotly.io as pio  # pylint: disable=import-outside-toplevel

        if not hasattr(self._obbject.chart, "fig"):
            raise ValueError(
                "Error: No chart has been created. Please create a chart first."
            )
        current = self._charting_settings.chart_style
        new = "light" if current == "dark" else "dark"
        self._charting_settings.chart_style = new

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Inspect exc.__cause__ to get the real underlying error
  2. Pre-convert data to a clean numeric DataFrame and call create_line_chart or to_chart(data=df) directly
  3. Check data is not empty and has at least one numeric column before charting

Example fix

# before
obj.charting.to_chart(data=weird_nested_dict)

# after
df = pd.DataFrame(weird_nested_dict['rows'])
obj.charting.to_chart(data=df)
Defensive patterns

Strategy: try-catch

Validate before calling

df = convert_to_basemodel(data)
assert df is not None and not df.empty, 'cannot build generic chart from empty data'

Try / catch

try:
    obj.charting.to_chart(data=data)
except RuntimeError as e:
    root = e.__cause__  # real underlying exception
    logging.error('to_chart failed: %s', root)

Prevention

When it happens

Trigger: Calling obbject.charting.to_chart() with data that converts to an empty or fully non-numeric DataFrame; passing data kwarg of unsupported type (nested dicts, scalar) that breaks basemodel_to_df; specific chart view failed and generic line chart cannot handle the shape.

Common situations: Non-tabular API results auto-charted; None/NaN-only frames after dropna; custom data structures passed as data kwarg.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/a1084e29ed415673. Report an issue: GitHub.