JavaScript C3js row data, custom colors

I'm using c3js to make a chart with row data and want to use specific colours.

var chart = c3.generate({
    data: {
        x:'x',
        rows: [
             ['x','Winter 2007-2008','Winter 2008-2009','Winter 2009-2010'],
             ['2013-01-01',12,30,3],
             ['2013-01-02',123,200,22],
             ['2013-01-03',21,100,54],
             ['2013-01-04',32,400,23],
             ['2013-01-05',12,150,12],
             ['2013-01-06',34,250,15]
        ],
    },
    axis: {
        x: {
            type: 'timeseries',
            tick: {
                format: '%Y-%m-%d'
            }
        }
    }
});

This is all good, except I wish to set each line as a custom colour.

With column data, this is simple:

data: {
    x:'x',
    columns:[[]]
},
color: {
        pattern: ['#1f77b4', '#aec7e8', '#ff7f0e']
}

Can this be achieved with row-oriented data?

Answer:1

Try setting color function to the chart as shown below:-

    color: function (color, d) {
        // d will be 'id' when called for legends
        var colors = {           // Mapping for dataseries to color code.
            'Winter 2007-2008': '#ff0000',
            'Winter 2008-2009':'#00ff00',
            'Winter 2009-2010':'#0000ff'
        };
        if(typeof d === 'object') {
            return colors[d.id];
        }else {
            return colors[d];
        }
        //return d.id && d.id === 'data3' ? d3.rgb(color).darker(d.value / 150) : color;
    }

Working example:- jsFiddle

Answer:2

According to the wow.js documentation I can set the bottom offset at which the animation will trigger: wow = new WOW( { boxClass: 'wow', // default animateClass: 'animated'...

According to the wow.js documentation I can set the bottom offset at which the animation will trigger: wow = new WOW( { boxClass: 'wow', // default animateClass: 'animated'...

i have a link with ui-sref attribute and also a jQuery touch event, but the problem is that when i click on this element the jQuery handler is running but the ui-sref not. Jquery: $('#fa-bar, #...

i have a link with ui-sref attribute and also a jQuery touch event, but the problem is that when i click on this element the jQuery handler is running but the ui-sref not. Jquery: $('#fa-bar, #...

  1. angular ui-sref not working

I am new to Angular and have a situation where I must pass in an object into an attribute of an element inside an ng-repeat. The code works fine when returning the new object if I do not use ajax to ...

I am new to Angular and have a situation where I must pass in an object into an attribute of an element inside an ng-repeat. The code works fine when returning the new object if I do not use ajax to ...

  1. angularjs infdig error
  2. infdig angular error
  3. angular rootscope infdig error

i am new in Phonegap development. In my current project, i want to get user profile name, gmail and email address. I know how to retrieve these information in native Android. By using which plugin, i ...

i am new in Phonegap development. In my current project, i want to get user profile name, gmail and email address. I know how to retrieve these information in native Android. By using which plugin, i ...