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.

4
  • 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) stackoverflow.com/questions/23609171/… Commented Dec 2, 2016 at 12:24
  • I selected element, but it not have getPointsAtEvent function ;/ Commented Dec 2, 2016 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. chartjs.org/docs Commented Dec 2, 2016 at 13:48
  • Can You be alittle bit more specific. Im really not js guy, and i have no clue what to do next... Commented Dec 2, 2016 at 14:18

1 Answer 1

0
        console.log(points);

instead

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

It was that easy;/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.