set different colors for each column in highcharts

后端 未结 4 1521
无人共我
无人共我 2020-11-29 05:53

I need to set different colors for each column in Highcharts graph dynamically. My Highcharts graph is:

options = {
           


        
4条回答
  •  清歌不尽
    2020-11-29 06:07

    Try either of these approaches:

    Approach 1:

    Highcharts.setOptions({ colors: ['#3B97B2', '#67BC42', '#FF56DE', '#E6D605', '#BC36FE'] });
    

    Approach 2:

    var colors = ['#3B97B2', '#67BC42', '#FF56DE', '#E6D605', '#BC36FE', '#000'];
    
     $('#bar_chart').highcharts({
            chart: {
                type: 'column'              
            },
            title: {
                text: ''
            },
            subtitle: {
                text: ''
            },
            xAxis: {
                type: 'category'
            },
            yAxis: {
                title: {
                    text: ''
                }
            },
            legend: {
                enabled: false
            },
            plotOptions: {
                series: {
                    borderWidth: 0,
                    dataLabels: {
                        enabled: false                       
                    }
                }
            },         
    
            series: [{
                name: '',
                colorByPoint: true,
                data: [{
                    name: 'Blue',
                    y: 5.78,
                    color: colors[0]
    
                }, {
                    name: 'Green',
                    y: 5.19,
                    color: colors[1]
    
                }, {
                    name: 'Pink',
                    y: 32.11,
                    color: colors[2]
    
                }, {
                    name: 'Yellow',
                    y: 10.04,
                    color: colors[3]
    
                }, {
                    name: 'Purple',
                    y: 19.33,
                    color: colors[4]
    
                }]
            }]
        });
    

提交回复
热议问题