I currently have a simple donut chart that I created with C3. I have put it inside a directive and all works fine.
My directive is as follows:
angular.module('dashboardApp').directive('donutChart',function(){
function link(scope,element,attr){
scope.$watch(function() {
return scope.data;
},
function() {
if(scope.data !== undefined){
var chart = c3.generate({
bindto: 'donut-chart',
data:{
columns : scope.data,
type: 'donut'
},
donut:{
label : {
format: function(value,ratio,id){
return value;
},
}
},
tooltip:{
position: function(data,width,height,element){
return {top:-180,left:300}
}
},
});
}
}
)};
return {
restrict: 'EA',
scope: {
data: '='
},
link : link
};
});
In the HTML I have the following:
<div class="row">
<div class="donut-route" >
<donut-chart data='routes'></donut-chart>
</div>
</div>
My aim is to have the donut char re-size within the div it is currently sitting in.
I am aware of the C3 resize where I can pass values through and maybe I could add window sizes to the $scope.watch and resize it every time but I am not sure if that would be too heavy. From reading the documentation I think C3 graphs re-size automatically but due to the fact it's in a directive I think it is being restricted.
Any pointers or advice would be greatly appreciated.