Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set color of grouped stacked column in highcharts

Tags:

highcharts

I have a requirement to set the color of stack column chart in relation with previous stack. Consider this fiddle. http://jsfiddle.net/0n7g4a1e/

series: [{
        name: 'John',
        data: [5, 3, 4, 7, 2],
        stack: 'Actual'
    }, {
        name: 'John',
        data: [3, 4, 4, 2, 5],
        stack: 'Budget'
    }]

If Jane - Actual is light green, Jane - Budget should be dark green. This should be for all categories, Apple through bananas. similarly if John - Acutal is light blue, John - budget should be dark blue.

How can this be done? I dont want to specify each point color, i am fine with automatic color that gets selected, just that the bugdet series should have a shade darker than the actual.

Thanks.

like image 353
sagar Avatar asked Jan 27 '16 10:01

sagar


People also ask

How do you change the color of each column in a bar chart?

In a chart, click to select the data series for which you want to change the colors. On the Format tab, in the Current Selection group, click Format Selection. tab, expand Fill, and then do one of the following: To vary the colors of data markers in a single-series chart, select the Vary colors by point check box.

How do I change colors in Highcharts?

To change the background color of the chart you have to set in the chart. backgroundColor property. Bar colors in the series color property. Check the example with your chart I posted below.

What is plotOptions in Highcharts?

The plotOptions is a wrapper object for config objects for each series type. The config objects for each series can also be overridden for each series item as given in the series array. Configuration options for the series are given in three levels. Options for all series in a chart are given in the plotOptions.

What is stack in Highcharts?

Stacked charts are often used to visualize data that accumulates to a sum. This chart is showing data labels for each individual section of the stack.


1 Answers

You need to set colors for Highcharts in that way, for example, basing on default colors:

var colors = Highcharts.getOptions().colors.slice(0), // get default colors
    dark = -0.5;


colors[1] = Highcharts.Color(colors[0]).brighten(dark).get(); // using Highcharts.Color(), get darker golor, using first color as base

colors[3] = Highcharts.Color(colors[2]).brighten(dark).get();

Now just set this colors:

$('#container').highcharts({

    chart: {
        type: 'column'
    },

    colors: colors,

Demo: http://jsfiddle.net/0n7g4a1e/2/

like image 97
Paweł Fus Avatar answered Nov 06 '22 04:11

Paweł Fus