You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PlotlyChart交互失效与PieChart AttributeError问题求助

加密货币统计应用图表问题求助

一、PlotlyChart无交互问题

开发一款展示加密货币交易所统计数据的自用应用,当前使用PlotlyChart展示的图表完全无交互性,无法实现Plotly原生图表的筛选数据、hover显示详细统计等功能,希望解决交互问题或排查操作是否有误。

二、PieChart报错问题

报错信息

Unhandled error processing page session 054db3bc-f572-42c1-be03-8cd60e4f84c6: Traceback (most recent call last):
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_runtime\app.py", line 357, in on_session_created
    session_handler(page)
  File "D:\IT_Trading\1.Мой проект\Robofin_io\app.py", line 16, in __init__
    self.init_helper()
  File "D:\IT_Trading\1.Мой проект\Robofin_io\app.py", line 20, in init_helper
    self.page.go("/Statistics")
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\page.py", line 549, in go
    self.update()
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\page.py", line 290, in update
    r = self.__update(self)
        ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\page.py", line 422, in __update
    commands, added_controls, removed_controls = self.__prepare_update(*controls)
                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\page.py", line 447, in __prepare_update    
    control.build_update_commands(
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\control.py", line 396, in build_update_commands
    innerCmds = ctrl._build_add_commands(
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\control.py", line 451, in _build_add_commands
    childCmd = control._build_add_commands(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\control.py", line 451, in _build_add_commands
    childCmd = control._build_add_commands(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\control.py", line 451, in _build_add_commands
    childCmd = control._build_add_commands(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 6 more times]
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\control.py", line 440, in _build_add_commands
    command = self._build_command(False)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\control.py", line 467, in _build_command
    self._before_build_command()
  File "C:\Users\root\AppData\Local\Programs\Python\Python311\Lib\site-packages\flet_core\plotly_chart.py", line 119, in _before_build_command
    svg = self.__figure.to_image(format="svg").decode("utf-8")
          ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'PieChart' object has no attribute 'to_image'

触发报错的代码片段

def click_graph(self):
    normal_radius = 50
    hover_radius = 60
    normal_title_style = TextStyle(
        size=16, color=colors.WHITE, weight=FontWeight.BOLD
    )
    hover_title_style = TextStyle(
        size=22,
        color=colors.WHITE,
        weight=FontWeight.BOLD,
        shadow=BoxShadow(blur_radius=2, color=colors.BLACK54),
    )

    def on_chart_event(e: PieChartEvent):
        for idx, section in enumerate(chart.sections):
            if idx == e.section_index:
                section.radius = hover_radius
                section.title_style = hover_title_style
            else:
                section.radius = normal_radius
                section.title_style = normal_title_style
        chart.update()

    chart = PieChart(
        sections_space=0,
        center_space_radius=40,
        on_chart_event=on_chart_event,
        expand=True,
    )

    pnl = []

    graph_data = data_active()
    [pnl.append(graph_data[sym]) for sym in graph_data]
    for sym in graph_data:
        percent = round((graph_data[sym] * 100 / sum(pnl)))
        pie_chart = PieChartSection(
            percent,
            title=f"{sym} {percent}%",
            title_style=normal_title_style,
            radius=50
        )
        chart.sections.append(pie_chart)

    return chart

图表嵌套展示结构

Row -> Container -> Column -> Column -> Container -> Column -> Container -> 图表内容

内容的提问来源于stack exchange,提问作者Павел Дмитриев

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 04:45:00