javascript - Angular 图饼图数据点击事件

标签 javascript jquery angularjs angular-chart

Angular JS 图表很棒,但我需要在我创建的饼图中实现点击事件..这是编码..

这是 JavaScript 编码...

  $scope.pied = [{
          value: 4,
          color: "#FF5A5E",
          highlight: "#FF5A5E",
          label: "Prospective"
        }, {
          value: 0,
          color: "#46BFBD",
          highlight: "#46BFBD",
          label: "Pending"
        }, {
          value: 0,
          color: "#FDB45C",
          highlight: "#FDB45C",
          label: "CallBacks"
        }, {
          value: 4,
          color: "#e6e6fa",
          highlight: "#e6e6fa",
          label: "FollowUp"
        }, {
          value: 1,
          color: "#cc5229",
          highlight: "#cc5229",
          label: "Not Interested"
        }, {
          value: 0,
          color: "#556b2f",
          highlight: "#556b2f",
          label: "Close"
        }]

        var pieOptions = {
          //Boolean - Whether we should show a stroke on each segment
          segmentShowStroke: true,

          //String - The colour of each segment stroke
          segmentStrokeColor: "#fff",

          //Number - The width of each segment stroke
          segmentStrokeWidth: 2,

          //Boolean - Whether we should animate the chart
          animation: true,

          //Number - Amount of animation steps
          animationSteps: 100,

          //String - Animation easing effect
          animationEasing: "easeOutBounce",

          //Boolean - Whether we animate the rotation of the Pie
          animateRotate: true,

          //Boolean - Whether we animate scaling the Pie from the centre
          animateScale: false,

          //Function - Will fire on animation completion.
          onAnimationComplete: null

        }
        var ctx = document.getElementById("pieChart").getContext("2d");
        var myPieChart = new Chart(ctx).Pie($scope.pied, pieOptions);
        ctx.onclick = function(evt){
        var activePoints = myPieChart.getPointsAtEvent(evt);
        console.log("active: "+activePoints);
        // => activePoints is an array of points on the canvas that are at the same position as the click event.
    };
        document.getElementById('js-legend').innerHTML = myPieChart.generateLegend();
This is the HTML Coding..
 <canvas id="pieChart" width="440" height="200" ></canvas>
   <div id="js-legend" class="chart-legend"></div>
这是上面程序的图像..我已经编写了代码,当我单击 The FollowUP 时,它必须与之相关的数据..但是单击事件不起作用..?

enter image description here

请查看上面的代码和图片,并指导我获得我期望的确切输出。预先感谢大家...

最佳答案

我使用了 angular-chart.js 来代替这个 chart.js Angular JS 文档是 here 。 Angular Chart 比 Chart.js 稍微简单一点..

感谢大家的支持..:)

关于javascript - Angular 图饼图数据点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35648315/

相关文章:

javascript - 垂直或水平文本的搜索功能

javascript - 同时执行 JS 函数

javascript - 覆盖 jquery 验证插件中的函数

ios - Angular 指令在 iPhone 4s 上无法正常工作

angularjs - 将 Angular 2 与 VS2015 Update 2 一起使用 - 获取 npm - 未安装错误

javascript - 在 jQuery-UI Datepicker 中选择日期范围

javascript - 是否有使用 RxJS 的此可写流的功能更强大的实现,在处理之前等待 promise 解决?

php - PHP 中数据表的计数和最大值

jquery - jQuery 插件所需的 CSS 定位帮助 - 提供的 jsfiddle 示例

javascript - ng-click 事件显示未定义