【问题标题】:Column based Highchart drilldown series assign color code to each column基于列的 Highchart 向下钻取系列为每列分配颜色代码
【发布时间】:2018-08-07 11:43:59
【问题描述】:

我想为基于列的图表的钻取图的每一列分配我自己的颜色。所以我根据一些预先计算创建了区域并分配了颜色代码。

我的代码如下:

Highcharts.chart('container', {
    chart: {
        type: 'column'
    },
    title: {
        text: 'Browser market shares. January, 2015 to May, 2015'
    },
    subtitle: {
        text: 'Click the columns to view versions. Source: <a href="http://netmarketshare.com">netmarketshare.com</a>.'
    },
    xAxis: {
        type: 'category'
    },
    yAxis: {
        title: {
            text: 'Total percent market share'
        }

    },
    legend: {
        enabled: false
    },
    plotOptions: {
        series: {
            borderWidth: 0,
            dataLabels: {
                enabled: true,
                format: '{point.y:.1f}%'
            }
        }
    },

    tooltip: {
        headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
        pointFormat: '<span style="color:{point.color}">{point.name}</span>: <b>{point.y:.2f}%</b> of total<br/>'
    },

    series: [{
        name: 'Brands',
        colorByPoint: true,
        data: [{
            name: 'Microsoft Internet Explorer',
            y: 56.33,
            drilldown: 'Microsoft Internet Explorer'
        }, {
            name: 'Firefox',
            y: 10.38,
            drilldown: 'Firefox'
        }]
    }],
    drilldown: {
        series: [{
            name: 'Microsoft Internet Explorer',
            id: 'Microsoft Internet Explorer',
            data: [
                [
                    'v11.0',
                    14 // Over max set in zone get default color
                ],
                [
                    'v8.0',
                    10
                ],
                [
                    'v6.0',
                    8
                ],
                [
                    'v7.0',
                    4
                ]
            ],
            zones: [{
                color: '#ffcc00'
            }, {
                color: '#AA7F39'
            }, {
                color: '#ff8000'
            }, {
                color: '#FFFF00'
            }]
        }, {
            name: 'Firefox',
            id: 'Firefox',
            data: [
                [
                   'v35',
                    12,

                ],
                [
                    'v34',
                    10
                ],
                [
                    'v38',
                    7
                ],
                [
                    'v33',
                    4
                ],
                [
                    'v32',
                    3
                ]
            ],
            zones: [{
                color: '#FFFF00'
            }, {
                color: '#FFFF00'
            }, {
                color: '#ff8000'
            }, {
                color: '#AA7F39'
            }]
        }]
    }
});

我的小提琴是

https://jsfiddle.net/jqefrrj0/

现在,当我单击 Microsoft 时,下钻图具有所有黄色列,而我希望它根据区域中给出的每种颜色进行更改。

首先是黄色,然后是芥末色、橙色、黄色。

我怎样才能为钻取系列的每一列实现上述颜色。

【问题讨论】:

    标签: javascript highcharts colors column-chart


    【解决方案1】:

    你忘了设置zones.value Documentation

            zones: [{
                color: '#ffcc00',
                value:5
            }, {
                color: '#AA7F39',
                value:12
            }, {
                color: '#ff8000'
            }, {
                color: '#FFFF00'
            }]
    

    Updadted Fiddle

    【讨论】:

    • 是的,我可以不设置值吗?很少有相同值的东西可以有不同的颜色,具体取决于其他一些参数
    • 请在这篇文章的答案下查看我的最后一条评论:stackoverflow.com/questions/48660900/…
    • @KamilKulig 您正在根据数据集中的参数分配颜色。如果我已经为每个向下钻取列设置了预定义颜色,我只想将它分配给相应的列
    • 你为什么不在点的选项里做呢?示例(深入到 Microsoft Internet Explorer):jsfiddle.net/BlackLabel/y8jntmfw
    • @KamilKulig 这正是我想要的。我试过但用 [ ] 它给了我错误。非常感谢!!!!
    猜你喜欢
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    相关资源
    最近更新 更多