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

如何将Pyecharts中DataView的文本及按钮从中文改为英文?

切换Pyecharts DataView文本及按钮至英文

要将DataView的头部标题、关闭/确认按钮从中文改为英文,需在toolbox_opts的dataView配置中添加lang参数,自定义英文文本。以下是修改后的完整代码及关键说明:

修改后的代码

line_chart_Traffic_Vol_DL = (
    Line()
    .add_xaxis(df3.Date.tolist())
    .add_yaxis(
        'Traffic_Vol_DL',
        df3['Traffic_Vol_DL'].tolist(),
        is_smooth=True,
        is_connect_nones=True,
        linestyle_opts=opts.LineStyleOpts(color='blue', width=1),
        markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_='average')]),
        markpoint_opts=opts.MarkPointOpts(
            data=[
                opts.MarkPointItem(type_='max', name='Max'),
                opts.MarkPointItem(type_='min', name='Min')
            ]
        ),
    )
    .set_series_opts(
        areastyle_opts=opts.AreaStyleOpts(opacity=0.05, color='#c6f'),
        label_opts=opts.LabelOpts(is_show=False)
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title='Traffic_Vol_DL', subtitle='GB'),
        datazoom_opts=[opts.DataZoomOpts(), opts.DataZoomOpts(type_='inside')],
        tooltip_opts=opts.TooltipOpts(trigger='axis'),
        legend_opts=opts.LegendOpts(is_show=False),
        toolbox_opts=opts.ToolboxOpts(
            is_show=True,
            feature={
                'restore': {'title': 'Restore'},
                'saveAsImage': {'title': 'Save'},
                'dataView': {
                    'title': 'Data View',
                    'lang': ['Data View', 'Close', 'Confirm']
                }
            }
        )
    )
)

核心修改点

  • 在dataView配置中添加lang列表:三个元素依次对应DataView头部标题、关闭按钮文本、确认按钮文本,直接替换默认中文。
  • 将dataView的title字段改为Data View,保持界面文本统一。

修改完成后,DataView的头部将显示"Data View",两个操作按钮分别显示"Close"和"Confirm",完全切换为英文界面。

内容的提问来源于stack exchange,提问作者mars lee

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 17:05:28