This example shows you how to use the getOpenSegment() function to retrieve information about the currently open segment. Click on a segment then on the "Get the Open Segment" button.
var pie = new d3pie("pie", {
header: {
title: {
text: "Another pie chart"
}
},
labels: {
inner: {
format: "value"
},
value: {
color: "#ffffff"
}
},
data: {
content: [
{ label: "One", value: 0.1 },
{ label: "Two", value: 0.56 },
{ label: "Three", value: 0.12 },
{ label: "Four", value: 0.4 },
{ label: "Three", value: 0.51 },
{ label: "Three", value: 0.2 }
]
}
});
$(function() {
$("#btn").on("click", function() {
var segment = pie.getOpenSegment();
if (segment === null) {
alert("No segment open. Click on a segment then re-click the button.");
} else {
alert("Segment open. View the console to see full details about the segment.");
console.log(segment);
}
});
});