【问题标题】:Coloring column series in django-graphos google Chartdjango-graphos google Chart中的着色列系列
【发布时间】:2016-11-12 16:44:21
【问题描述】:

如何在 django-graphos google Column Chart 中为每个列系列设置颜色?

要做到这一点,谷歌图表在文档中有这个 (https://developers.google.com/chart/interactive/docs/gallery/columnchart#coloring-columns)

    var data = google.visualization.arrayToDataTable([
         ['Element', 'Density', { role: 'style' }],
         ['Copper', 8.94, '#b87333'],            // RGB value
         ['Silver', 10.49, 'silver'],            // English color name
         ['Gold', 19.30, 'gold'],
    ]);

但是当我在 django-graphos 的数据数组中使用它时

 data = [
             ['Type', 'Amount', { role: 'style' }],
             ['Current Month', 2000, '#b87333'],            // RGB value
             ['Previous Month', 3000, 'silver'],            // English color name
        ]

我收到此错误:给定轴上的所有系列必须是相同的数据类型。

我应该怎么做才能在 django-graphos 中为谷歌柱形图的每个列系列设置不同的颜色?

谢谢

【问题讨论】:

  • 为每个 'Element' 使用一列,而不是一行 -- 然后使用 colors 配置选项

标签: django graph google-visualization


【解决方案1】:

为了实现这一点,我首先像这样修改数组:

 data = [
         ['Type', 'Amount', 'Amount'],
         ['Current Month', 2000, None],
         ['Previous Month', None, 3000],
 ]

然后我添加这些选项:

chart = ColumnChart(SimpleDataSource(data=data), options= {
                                             'isStacked': True,
                                             'legend': {
                                                 'position': 'none'
                                              }, 'series': [
                                                   {'color': '#0084cgg'},
                                                   {'color': '#ef4036'}                                                      
                                              ]
                                          })

通过这个选项,我设法为每个系列着色

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多