function offset(element) {
var display = element[0].style.display;
if(display === 'none') {
element[0].style.display = 'block';
}
var boundingClientRect = element[0].getBoundingClientRect();
element[0].style.display = display;
return {
width: boundingClientRect.width || element.prop('offsetWidth'),
height: boundingClientRect.height || element.prop('offsetheight'),
top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop),
left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft)
}
}angular.directive('svgResize', ['$window', function ($window) {
return {
restrict: 'A',
scope: { chart: '=' }, // need reference to the dc chart
link: function (scope, elem, attrs) {
function resize() {
d3.select(attrs.selector + ' svg').attr('width', '100%');
scope.chart.redraw();
}
// using lodash debounce
$window.addEventListener('resize', _.debounce(resize, 300));
}
}]);
<div id='mychart'>
<svg svg-resize chart='mychart' selector='mychart'>
</div>
elem.attr('width', '100%'); // using jQLite .attr() to try to set the width
elem[0].setAttribute('width', '100%'); // using vanilla dom api to try to set the width
d3.select(elem[0]).attr('width', '100%'); // using d3.select and pass the reference
charts.salesLine
.height(160)
.margins({top: 20, left: 50, right: 20, bottom: 20})
.dimension(dim.day)
.group(grp.discountRollup, 'Discount')
.renderArea(true)
.x(d3.time.scale().domain([beginDay, endDay]))
.xUnits(d3.time.days)
.valueAccessor(function (d) {
return d.value.discount_total;
})
.elasticX(true)
.elasticY(true)
.brushOn(true)
.legend(dc.legend())
.yAxis().tickFormat(dollarLabel);
chart = new dc.pieChart(this.getChartId(), this.getChartGroup())
.legend(dc.legend());
chart.on('preRender', function (chart) {
chart.radius(null);
}); <div id="chart1" class="dc-chart" style="float: inherit !important;"/></div>function resize() { chart3.root().select('svg') .attr('height', chart3.height()) .attr('width', chart3.width()); chart3.redraw();} _chart.data = function(d) { if (!arguments.length) return _data.call(_chart,_group); _data = d3.functor(d); _chart.expireCache(); return _chart; };
_chart.data(function(group) { if (_cap == Infinity) { return _chart._computeOrderedGroups(group.all()); } else { var topRows = group.top(_cap); // ordered by crossfilter group order (default value) topRows = _chart._computeOrderedGroups(topRows); // re-order using ordering (default key) if (_othersGrouper) return _othersGrouper(topRows); return topRows; } });