Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. Chart.types.Pie.extend({
  2. name: "PieUnique",
  3. addData: function (segment, atIndex, silent) {
  4. var index = atIndex || this.segments.length;
  5. this.segments.splice(index, 0, new this.SegmentArc({
  6. value: segment.value,
  7. outerRadius: (this.options.animateScale) ? 0 : this.outerRadius,
  8. innerRadius: (this.options.animateScale) ? 0 : (this.outerRadius / 100) * this.options.percentageInnerCutout,
  9. fillColor: segment.color,
  10. highlightColor: segment.highlight || segment.color,
  11. showStroke: this.options.segmentShowStroke,
  12. strokeWidth: this.options.segmentStrokeWidth,
  13. strokeColor: this.options.segmentStrokeColor,
  14. startAngle: Math.PI * this.options.startAngle,
  15. circumference: (this.options.animateRotate) ? 0 : this.calculateCircumference(segment.value),
  16. label: segment.label,
  17. //add option passed
  18. id: segment.id
  19. }));
  20. if (!silent) {
  21. this.reflow();
  22. this.update();
  23. }
  24. },
  25. });
  26.  
  27. var pieData = [{
  28. value: 300,
  29. color: "#F7464A",
  30. highlight: "#FF5A5E",
  31. label: "Red",
  32. id: "1-upi"
  33. }, {
  34. value: 50,
  35. color: "#46BFBD",
  36. highlight: "#5AD3D1",
  37. label: "Green",
  38. id: "2-upi"
  39. }, {
  40. value: 100,
  41. color: "#FDB45C",
  42. highlight: "#FFC870",
  43. label: "Yellow",
  44. id: "3-upi"
  45. }, {
  46. value: 40,
  47. color: "#949FB1",
  48. highlight: "#A8B3C5",
  49. label: "Grey",
  50. id: "4-upi"
  51. }, {
  52. value: 120,
  53. color: "#4D5360",
  54. highlight: "#616774",
  55. label: "Dark Grey",
  56. id: "5-upi"
  57. }];
  58.  
  59. var ctx = document.getElementById("chart-area").getContext("2d");
  60. window.myPie = new Chart(ctx).PieUnique(pieData);
  61.  
  62. document.getElementById("chart-area").onclick = function (evt) {
  63. var activePoints = window.myPie.getSegmentsAtEvent(evt);
  64.  
  65. if (activePoints[0]) {
  66. var label = activePoints[0].label;
  67. var value = activePoints[0].value;
  68. var id = activePoints[0].id;
  69.  
  70. alert('label = ' + label + ' | value = ' + value + ' | id = ' + id);
  71. }
  72. };
  73.  
  74. I expect to create the same funcionality but in Bar type.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement