I have implemented a C3.js chart in an Angular 2 application but the style in the C3.css file is not being applied to it. I know it is loading (I event copied it all into my component's scss file) but still doesnt work. Is it because the chart loads after css? Does anyone know how to solve this?
I get the data for the chart asynchronously in ngOnInit so I am thinking that the css is applied before the chart is drawn (which happens when the data is received). I am also thinking that it could be something with Angular throwing off the selectors.
ngOnInit() {
// draw pie chart
this.bitcoinService.getMapData()
.subscribe(data => {
var pieChartData = this.formatPieChartData(data);
this.pieChartInit(pieChartData); // call this.pieChartInit
})
}
pieChartInit(data) {
var chart = c3.generate({
data: {
columns: data, // example: [['data1', 30], ['data2', 120]]
type: 'pie'
}
});
I copied the C3 css right into my scss which is included like this which works for everything else in my component:
@Component({
moduleId: module.id,
selector: 'bitcoin-dashboard',
styles: [require('./bitcoin-dashboard.component.scss')],
template: require('./bitcoin-dashboard.component.html')
})
Also, when I d3.select an element of the chart after pieChartInit is called, the styling works. Example:
d3.selectAll('.c3-chart-arc path').style('stroke', 'white')
Any help is greatly appreciated!