c3.js change color pattern after generating chart

1.6k Views Asked by At

In c3.js I can load custom color pattern when generating chart. Is there any way to change it after I generated chart? I know there is color function but I can't really use it because c3 sends id of the sequence that it wants to know color for, not its order.

2

There are 2 best solutions below

1
yavalvas On

There is an issue on github here: c3 github thread which can be usefull for you.

0
ABJ On

I had to color y axix lines. I gave each of them a class and them later on change the label color and line color by

var chart = c3.generate(...
            onrendered: function(){
                if(lines){
                    for(var i=0; i < lines.length; i++){
                        d3.select("g." + lines[i].class + " line").style({stroke: lines[i].color, fill: lines[i].color});
                        d3.select("g." + lines[i].class + " text").style({stroke: lines[i].color, fill: lines[i].color});
                    }
                }                   
            }
        });