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

dash_cytoscape使用line-gradient-stop-colors实现边渐变失效求助

你代码中缺失了启用边渐变的核心配置项,调整后即可正常显示渐变效果:

修复要点

  • 边样式中必须显式指定line-fill属性值为linear-gradient,该属性默认值为纯色填充,是渐变不生效的核心原因
  • 可选配置line-gradient-direction调整渐变方向,默认值为to-target(从边的源节点指向目标节点渐变)
  • 若调整后仍无效果,可升级dash_cytoscape到最新版本:pip install --upgrade dash_cytoscape

调整后的样式配置

style_1 = [
    {
        'selector': 'node',
        'style': {
            'label': 'data(id)',
            'background-color': 'blue',
        }
    },
    {
        'selector': 'edge',
        'style': {
            # 启用边的线性渐变填充
            'line-fill': 'linear-gradient',
            'line-gradient-stop-colors': 'cyan magenta yellow',
            'line-gradient-stop-positions': '25 50 75',
            # 可选:指定渐变方向,默认即为to-target
            'line-gradient-direction': 'to-target'
        }
    }
]

替换原有样式表后重新运行代码,即可看到边的三色渐变效果。如果后续需要给边添加箭头,箭头颜色不会自动继承渐变,需要单独指定source-arrow-color和target-arrow-color属性。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 00:45:05