jettro / c3-angular-directive

Contains angularjs directives that use c3js to create good looking graphs
http://jettro.github.io/c3-angular-directive/
MIT License
203 stars 98 forks source link

Pass dynamic data to chart-events on-click-data #166

Closed sympmarc closed 7 years ago

sympmarc commented 7 years ago

I'm trying to generate a set of donut charts using ngRepeat from an object containing all of the parameters. This is working great except for one thing.

I'd like to pass an additional parameter to the chart-events on-click-data, as you can see in my code below. I can't seem to come up with a format for passing the key successfully. It doesn't seem as though Angular is able to inject the correct value in the on-click-data function. Any ideas?

Great work here, by the way. Open source is a thankless task!

<div ng-repeat="(key, value) in donuts">
    <div>
        <c3chart bindto-id="donut-{{key}}" chart-data="value.data" chart-columns="value.columns">
            <chart-events on-click-data="setFilter('{{key}}', data)" />
            <chart-size chart-height="150" chart-width="150" />
            <chart-legend show-legend="false" />
            <chart-donut title="{{value.title}}" width="35" label-format-function="formatLabel" />
        </c3chart>
    </div>
    <div class='mam-filter-value' ng-class="{ set: filters['{{key}}'] !== null }" ng-bind="filters['{{key}}']" ng-click="clearFilter('{{key}}')"></div>
</div>
sympmarc commented 7 years ago

And, of course, as soon as I added the issue above, I knew what I was doing wrong. Nothing to do with this great library - just my own stupidity!

In case it helps anyone else:

<div ng-repeat="(key, value) in donuts">
    <div>
        <c3chart bindto-id="{{key}}" chart-data="value.data" chart-columns="value.columns">
            <chart-events on-click-data="setFilter(key, data)" />
            <chart-size chart-height="150" chart-width="150" />
            <chart-legend show-legend="false" />
            <chart-donut title="{{value.title}}" width="35" label-format-function="formatLabel" />
        </c3chart>
    </div>
    <div class='mam-filter-value' ng-class="{ set: filters['{{key}}'] !== null }" ng-bind="filters['{{key}}']" ng-click="clearFilter(key)"></div>
</div>

and

$scope.setFilter = function(filterName, data) {
   $scope.filters[filterName] = data.id;
   $scope.applyFilters();
}