高图 - 颜色取决于值

时间:2016-06-08 10:26:18

标签: highcharts

我想根据它们的值给出条形颜色。

  1. 例如,如果你的条形值为5000,那么颜色应该是暗红色,类似于3000黑暗,而不是5000巴的值,所以...

  2. 我想在所有条形图上方添加100TB的总空间(条形图值上的一些文字)

    `   可用性条形图  

    $(function () {
        $('#container').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: 'Disk Utility'
            },
            subtitle: {
                text: 'Source: <a href="https://en.wikipedia.org/wiki/World_population">Application Name</a>'
            },
            xAxis: {
                categories: ['Checkout', 'Hermes', 'Hybris', 'Marketplace', 'Mobile'],
                title: {
                    text: null
                }
            },
            yAxis: {
                min: 0,
                title: {
                    text: 'Used (TB)',
                    align: 'high'
                },
                labels: {
                    overflow: 'justify'
                }
            },
            tooltip: {
                valueSuffix: ' millions'
            },
            plotOptions: {
                column: {
                    dataLabels: {
                                enabled: true,
                                color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
                                style: {
                                    textShadow: '0 0 3px black'
                                }
                            }
                }
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'top',
                x: -40,
                y: 80,
                floating: true,
                borderWidth: 1,
                backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
                shadow: true
            },
            credits: {
                enabled: false
            },
            series: [{
                data: [107, 311, 635, 203, 244]
            }]
        });
    });
    

    enter code here

  3. Fiddle

1 个答案:

答案 0 :(得分:4)

Here is updated fiddle

您可以使用plotoptions中的“Zones”来定义范围和相关颜色,如下面的代码所示:

zones: [{
        value: 200,  
        color: '#bdbdbd'  
    },{
        value:300,
        color: '#ff0000'  
    },
    {
        value:500,
        color: 'blue'  
    },{
        value:800,
        color: 'black'  
    }]