我在 Github 上找到了这个不错的画布派,但它给了我一些问题。我的JS不是很好,所以我在这里寻求帮助。 https://github.com/jamesalvarez/draggable-piechart
在此处显示的示例中,您可以看到用于操作图形的 UI。 https://codepen.io/Waterbear83/pen/vYOrbva?editors=0010
即使我使用相同的 js,我也不明白如何显示该 UI。 https://codepen.io/Waterbear83/pen/yLNqVBZ?editors=0010
有这么好心的人帮忙吗?
谢谢!
function onPieChartChange(piechart) {
var table = document.getElementById("proportions-table");
var percentages = piechart.getAllSliceSizePercentages();
var labelsRow = "<tr>";
var propsRow = "<tr>";
for (var i = 0; i < proportions.length; i += 1) {
labelsRow += "<th>" + proportions[i].format.label + "</th>";
var v = "<var>" + percentages[i].toFixed(0) + "%</var>";
var plus =
'<div id="plu-' +
dimensions[i] +
'" class="adjust-button" data-i="' +
i +
'" data-d="-1">+</div>';
var minus =
'<div id="min-' +
dimensions[i] +
'" class="adjust-button" data-i="' +
i +
'" data-d="1">−</div>';
propsRow += "<td>" + v + plus + minus + "</td>";
}
labelsRow += "</tr>";
propsRow += "</tr>";
table.innerHTML = labelsRow + propsRow;
var adjust = document.getElementsByClassName("adjust-button");
function adjustClick(e) {
var i = this.getAttribute("data-i");
var d = this.getAttribute("data-d");
piechart.moveAngle(i, d * 0.1);
}
for (i = 0; i < adjust.length; i++) {
adjust[i].addEventListener("click", adjustClick);
}
}