如何将绘图的“漏斗”仪表板转换为仪表板?

2024-04-19 17:48:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将这个简单的plotly漏斗式仪表板转换为仪表板:

from plotly import graph_objects as go

fig = go.Figure(go.Funnel(
    y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"],
    x = [39, 27.4, 20.6, 11, 2]))

fig.show()

输出:

enter image description here

我已经为Dash写了下面的代码,但是运气不好。你知道吗

import dash
import dash_core_components as dcc
import dash_html_components as html
from plotly import graph_objects as go

app = dash.Dash()


app.layout = html.Div([dcc.Figure(id='FunnelDashboard',
                    figure = {'data':[
                            go.Funnel(
                            y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"],
                            x = [39, 27.4, 20.6, 11, 2])]
                            }
                            )])

if __name__ == '__main__':
    app.run_server()

输出:

C:\Users\Test\Documents\Code>python Funnel_Dash.py
Traceback (most recent call last):
  File "Funnel_Dash.py", line 23, in <module>
    app.layout = html.Div([dcc.Figure(id='FunnelDashboard',
AttributeError: module 'dash_core_components' has no attribute 'Figure'

Tags: fromimportappgohtmlascomponents仪表板
1条回答
网友
1楼 · 发布于 2024-04-19 17:48:51

“Figure”不是“dash\u core\u components”的属性。你知道吗

我们可以用“图形”代替。你知道吗

app = dash.Dash()

app.layout = html.Div([dcc.Graph(id='FunnelDashboard',
                    figure = {'data':[
                            go.Funnel(
                            y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent"],
                            x = [39, 27.4, 26.6, 11, 2])]
                            }
                            )])
if __name__ == '__main__':
    app.run_server()

相关问题 更多 >