angular-chart.js icon indicating copy to clipboard operation
angular-chart.js copied to clipboard

Support StackedBar Extension

Open bhasden opened this issue 12 years ago • 4 comments

I'm not sure what the best way is of extending your current directives to support the StackedBar extension at https://github.com/Regaddi/Chart.StackedBar.js, but if you'd like add support directly it's pretty straightforward.

First, a new directive needs to be added:

.directive("chartStackedBar", function () { return chart('StackedBar'); });

Next, the click handler needs to be updated:

cvs.onclick = function (evt) {
    var click = chart.getPointsAtEvent || chart.getSegmentsAtEvent || chart.getBarsAtEvent;

    if (click) {
        var activePoints = click.call(chart, evt);
        scope.click(activePoints, evt);
    }
};

Finally, the hasDataSets method needs to be updated:

function hasDataSets(type) {
    return ['Line', 'Bar', 'Radar', 'StackedBar'].indexOf(type) > -1;
}

If you'd rather not add support directly into the current set of directives, could you suggest a way of extending the existing directives to support it?

bhasden avatar Nov 06 '14 05:11 bhasden

Code looks really neat. Definitely needs to allow using plugins but I'd rather have not to set dependencies for all external plugins so I need to think about how to make it extendable.

jtblin avatar Nov 06 '14 12:11 jtblin

I know it's been a while but it should now be possible to use the StackedBar extension (although I haven't tested). After you add the extension, you can set the chart type dynamically since https://github.com/jtblin/angular-chart.js/commit/080aed1449509fe5d8ca2027493a7d445d47d5c0, and since https://github.com/jtblin/angular-chart.js/commit/370b89db50838d871316e478332ed1883e03d532 the datasets should now automatically be detected. The onclick support for bar chart was fixed in https://github.com/jtblin/angular-chart.js/commit/2d5b982e9f23895261855c0635428597fa6a7917 which should also work for stacked bar charts.

jtblin avatar Jan 26 '15 06:01 jtblin

Worked as expected, add an example: http://jtblin.github.io/angular-chart.js/examples/stacked-bars.html

jtblin avatar Feb 22 '15 04:02 jtblin

Thank you for adding support for the StackedBar extension. It works great, except that formatting for the series attribute doesn't display properly. It just displays them stacked to the left with no color boxes. Would you provide a fix please?

brogers7 avatar May 19 '15 15:05 brogers7