0

I need to make chart that have onClick event and get label that was clicked. I found and adapt solution. This is my code:

    $scope.chart;
$scope.onClick = function (points, evt) {
    console.log(points, evt);
    if ($scope.chart) {
        console.log($scope.chart.getPointsAtEvent(evt));
    }
};

and view side:

       <canvas class="chart chart-horizontal-bar"
            chart-series="seriesPM"
            chart-labels="labelsPM"
            chart-data="dataPM"
            chart-options="chartOptions"
            chart-click="onClick"
            id="chart"
            ></canvas>

But my $scope.chart is undefined and i don't know how to get this variable.

Capitan Planet
  • 155
  • 3
  • 14
  • Your code never sets .chart equal to anything. It'll always be undefined. You need to set that .chart to something, probably using a selector. What that selector would be depends on what you're using. If you're using JQuery it's very straightforward (look up JQuery selectors), if you're just using Angular (so JQLite), then you'll need to look that up (here's a link) http://stackoverflow.com/questions/23609171/how-to-get-element-by-classname-or-id – Tim Consolazio Dec 02 '16 at 12:24
  • I selected element, but it not have getPointsAtEvent function ;/ – Capitan Planet Dec 02 '16 at 13:42
  • Right, but you would have to select and/or wrap it in such a way that the event is available. I looked this over and it should have everything you need to solve this. http://www.chartjs.org/docs/ – Tim Consolazio Dec 02 '16 at 13:48
  • Can You be alittle bit more specific. Im really not js guy, and i have no clue what to do next... – Capitan Planet Dec 02 '16 at 14:18

1 Answers1

0
        console.log(points);

instead

    if ($scope.chart) {
    console.log($scope.chart.getPointsAtEvent(evt));
}

It was that easy;/

Capitan Planet
  • 155
  • 3
  • 14