{"record":{"id":"d907b7b694a3e14c","repo":"OpenBB-finance/OpenBB","slug":"error-no-chart-has-been-created-please-create-a","errorCode":null,"errorMessage":"Error: No chart has been created. Please create a chart first.","messagePattern":"Error: No chart has been created\\. Please create a chart first\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"openbb_platform/obbject_extensions/charting/openbb_charting/charting.py","lineNumber":671,"sourceCode":"                    fig=fig, content=content, format=self._format\n                )\n                if render:\n                    return fig.show(**kwargs)  # type: ignore\n            except Exception as e:  # pylint: disable=W0718\n                raise RuntimeError(\n                    \"Failed to automatically create a generic chart with the data provided.\"\n                ) from e\n\n    def _set_chart_style(self, figure: \"Figure\"):\n        \"\"\"Set the user preference for light or dark mode.\"\"\"\n        return figure\n\n    def toggle_chart_style(self):\n        \"\"\"Toggle the chart style between light and dark mode.\"\"\"\n        import plotly.io as pio  # pylint: disable=import-outside-toplevel\n\n        if not hasattr(self._obbject.chart, \"fig\"):\n            raise ValueError(\n                \"Error: No chart has been created. Please create a chart first.\"\n            )\n        current = self._charting_settings.chart_style\n        new = \"light\" if current == \"dark\" else \"dark\"\n        self._charting_settings.chart_style = new\n        template_name = \"plotly_white\" if new == \"light\" else \"plotly_dark\"\n        figure = self._obbject.chart.fig  # type: ignore[union-attr]\n        figure.update_layout(template=pio.templates[template_name])  # type: ignore[union-attr]\n        self._obbject.chart.fig = figure  # type: ignore[union-attr]\n        self._obbject.chart.content = figure.show(  # type: ignore[union-attr]\n            external=True\n        ).to_plotly_json()  # type: ignore[union-attr]\n\n    @staticmethod\n    def _convert_to_string(x):\n        \"\"\"Sanitize the data for the table.\"\"\"\n        # pylint: disable=import-outside-toplevel\n        from numpy import isnan","sourceCodeStart":653,"sourceCodeEnd":689,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/obbject_extensions/charting/openbb_charting/charting.py#L653-L689","documentation":"Charting.toggle_chart_style() flips the current chart between plotly light/dark templates, but requires an existing chart figure stored on obbject.chart. If no chart was created yet (obbject.chart has no 'fig' attribute), there is nothing to restyle and this ValueError is raised.","triggerScenarios":"Calling obbject.charting.toggle_chart_style() before any .charting() or to_chart() call; chart creation previously failed so obbject.chart was never set; calling on a freshly built OBBject with manual results.","commonSituations":"User toggles dark mode in a notebook/script before generating a chart; charting threw earlier and the error was swallowed; interactive sessions where the chart cell ran out of order.","solutions":["Create a chart first: res = obb.equity.price.historical('AAPL'); res.charting(); res.charting.toggle_chart_style()","Guard with hasattr(res.chart, 'fig') before toggling","Set the preferred style in user settings/charting config up front so toggling is unnecessary"],"exampleFix":"# before\nres = obb.equity.price.historical('AAPL')\nres.charting.toggle_chart_style()\n\n# after\nres = obb.equity.price.historical('AAPL')\nres.charting()\nres.charting.toggle_chart_style()","handlingStrategy":"validation","validationCode":"if not hasattr(res.chart, 'fig'):\n    res.charting()  # create the chart first\nres.charting.toggle_chart_style()","typeGuard":"def chart_exists(res) -> bool:\n    return hasattr(res.chart, 'fig')","tryCatchPattern":"try:\n    res.charting.toggle_chart_style()\nexcept ValueError as e:\n    if 'No chart has been created' in str(e):\n        res.charting(); res.charting.toggle_chart_style()","preventionTips":["Always run .charting() before style toggling","Guard with hasattr(res.chart, 'fig')","Set chart_style preference in settings to avoid runtime toggling"],"tags":["openbb","charting","style-toggle","state-missing"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}