Hello,
I'm trying to use the following Highcharts directive with a carousel component.
Using my own template and Twitter's Bootstrap, I have the following:
<div id="chartCarousel1" class="carousel slide">
<div class="carousel-inner">
<div class="item chart"
ng-repeat="widget in widgets | filter: {type: 'chart'} | orderBy: 'order'"
ng-class="{active: $index == 0}">
<chart class="widget" value="{{widget}}" type="{{widget.chartType}}"></chart>
</div>
</div>
<a class="left carousel-control" href="#chartCarousel1" data-slide="prev"
ng-show="(widgets | filter: {type: 'chart'}).length > 1">‹</a>
<a class="right carousel-control" href="#chartCarousel1" data-slide="next"
ng-show="(widgets | filter: {type: 'chart'}).length > 1">›</a>
</div>
However, this results in the following error:
This seems to be caused by the following css in Bootstrap:
.carousel-inner > .item { display: none }
If I add an override with "display: block" to my stylesheet, everything works, but the charts are stacked instead of in a carousel. The good news is all the charts are rendered successfully.
A seemingly better solution is to modify the directive to show/hide the "item" element so Highcharts is able to write to it. The code for this is below:
link: function (scope, element, attrs) {
var chartsDefaults = {
chart: {
renderTo: element[0],
type: attrs.type || null,
height: attrs.height || null,
width: attrs.width || null
}
};
$(element[0]).parent().show();
//Update when charts data changes
scope.$watch(function () {
return attrs.value;
}, function (value) {
if (!attrs.value) return;
// We need deep copy in order to NOT override original chart object.
// This allows us to override chart data member and still the keep
// our original renderTo will be the same
var deepCopy = true;
var newSettings = {};
$.extend(deepCopy, newSettings, chartsDefaults, JSON.parse(attrs.value));
var chart = new Highcharts.Chart(newSettings);
if (scope.$index > 0) {
$(element[0]).parent().hide();
}
});
}
This seems to work (or at least stops the error), but only the first chart is written. The rest don't seem to be "activated" properly when I navigate to them. Probably because of something to do with hiding them. I've tried just setting "display" to block and none (instead of show and hide), but that doesn't seem to work either.
This same behavior happens when using the carousel directive from angular-ui-bootstrap.
Any ideas for a workaround?
Thanks,
Matt