Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Chart.types.Pie.extend({
- name: "PieUnique",
- addData: function (segment, atIndex, silent) {
- var index = atIndex || this.segments.length;
- this.segments.splice(index, 0, new this.SegmentArc({
- value: segment.value,
- outerRadius: (this.options.animateScale) ? 0 : this.outerRadius,
- innerRadius: (this.options.animateScale) ? 0 : (this.outerRadius / 100) * this.options.percentageInnerCutout,
- fillColor: segment.color,
- highlightColor: segment.highlight || segment.color,
- showStroke: this.options.segmentShowStroke,
- strokeWidth: this.options.segmentStrokeWidth,
- strokeColor: this.options.segmentStrokeColor,
- startAngle: Math.PI * this.options.startAngle,
- circumference: (this.options.animateRotate) ? 0 : this.calculateCircumference(segment.value),
- label: segment.label,
- //add option passed
- id: segment.id
- }));
- if (!silent) {
- this.reflow();
- this.update();
- }
- },
- });
- var pieData = [{
- value: 300,
- color: "#F7464A",
- highlight: "#FF5A5E",
- label: "Red",
- id: "1-upi"
- }, {
- value: 50,
- color: "#46BFBD",
- highlight: "#5AD3D1",
- label: "Green",
- id: "2-upi"
- }, {
- value: 100,
- color: "#FDB45C",
- highlight: "#FFC870",
- label: "Yellow",
- id: "3-upi"
- }, {
- value: 40,
- color: "#949FB1",
- highlight: "#A8B3C5",
- label: "Grey",
- id: "4-upi"
- }, {
- value: 120,
- color: "#4D5360",
- highlight: "#616774",
- label: "Dark Grey",
- id: "5-upi"
- }];
- var ctx = document.getElementById("chart-area").getContext("2d");
- window.myPie = new Chart(ctx).PieUnique(pieData);
- document.getElementById("chart-area").onclick = function (evt) {
- var activePoints = window.myPie.getSegmentsAtEvent(evt);
- if (activePoints[0]) {
- var label = activePoints[0].label;
- var value = activePoints[0].value;
- var id = activePoints[0].id;
- alert('label = ' + label + ' | value = ' + value + ' | id = ' + id);
- }
- };
- I expect to create the same funcionality but in Bar type.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement