【发布时间】:2019-07-22 18:19:46
【问题描述】:
我需要您的帮助来解决我的数据重组问题,我正在尝试使用 chartjs 和来自 xml 链接的动态数据创建一个图表,下面显示的代码有效,但不是我想要的确切方式。 在我目前的情况下,我得到“例如”ChefProjet=10,ChefProjet=7,ChefProjet=7,ChefProjet=7,所以 ChefProjet 重复了四次,但我想让 ChefProjet 只显示一次,它等于 31(10+ 7+7+7),你可以在图片的链接中看到图表。 ↓
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + add2,
method: "GET",
headers: { "Accept": "application/json; odata=nometadata" },
success: function (data) {
if (data.value.length > 0) {
var pieValues = [];
var pieLabels = [];
for (var i = 0; i < data.value.length; i++) {
pieValues.push(parseInt(data.value[i].AssignmentWork));
pieLabels.push(data.value[i].ResourceName);
}
var pieData = {
datasets: [{
borderColor: "#80b6f4",
pointBorderColor: "#80b6f4",
pointBackgroundColor: "#80b6f4",
pointHoverBackgroundColor: "#80b6f4",
pointHoverBorderColor: "#80b6f4",
pointBorderWidth: 1,
pointHoverRadius: 1,
pointHoverBorderWidth: 1,
pointRadius: 2,
fill: false,
borderWidth: 1,
data: pieValues
}],
labels: pieLabels
};
var ctx = document.getElementById("myChart");
if (window.myPieChart2 != undefined)
{
window.myPieChart2.destroy();
}
//
window.myPieChart2 = new Chart(ctx, {
type: 'line',
data: pieData,
options: {
responsive: true,
legend: { display: false },
title: {
display: true,
text: 'Pourcentage d\'achevement des phases'
},
scales: {
xAxes: [{
gridLines: {
zeroLineColor: "transparent"
},
ticks: {
maxRotation: 90,
minRotation: 90,
fontSize:10
}
}],
yAxes: [{
ticks: {
fontColor: "rgba(0,0,0,0.5)",
fontStyle: "bold",
beginAtZero: true,
maxTicksLimit: 5,
padding: 20
},
gridLines: {
drawTicks: false,
display: false
}
}]
}
}
});
}
},
error: function (data) {
}
});
感谢您的宝贵时间。
【问题讨论】:
标签: javascript xml dynamic chart.js