Highchart - colors depending on values

為{幸葍}努か 提交于 2019-12-13 02:37:38

问题


I want to give a color for bars depending on their values.

  1. For example if you a bar value 5000 then the color should be Dark RED similar for 3000 less darker than 5000 bar values so on...

  2. I want to add total space like 100TB above all bars(some text on my bar value)

    ` Availability Bar Chart

    $(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

Fiddle


回答1:


Here is updated fiddle

You can use "Zones" in plotoptions to define a range and relevant color , as per code below :

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


来源:https://stackoverflow.com/questions/37699882/highchart-colors-depending-on-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!