0
필자는 (y) 값에 따라 밑줄 JS로 정렬해야하는 코드를 아래에 있습니다.밑줄을 사용하여 내림차순 정렬 JS
아래 코드를 찾으십시오. 나는 먼저 오름차순으로 뒤집어 엎 으려고 노력하고있다. 불행히도, 그것은 나를 위해 정렬을 수행하지 않고 정렬없이 데이터를 보여줍니다. sortBy
function getMessageNames(){
var rowIter = 1;
//document.getElementById("demo2").innerHTML += "from getMessageNames="+calltypes;
for (var i in calltypes){
keyId = calltypes[i].label;
for (var index in keyMsgNames){
if(keyMsgNames[index].Id == keyId){
var row = {"label":keyMsgNames[index].Name,"y":calltypes[i].y};
messageNames.push(row);
break;
}
}
// Result:
//document.getElementById("demo2").innerHTML += "descending="+descending;
}
var ascending = _.sortBy(messageNames, ['y']);
// Then get DESC
var descending = ascending.reverse();
for (var index in descending){
addRow("CallTable", [ descending[index].label, descending[index].y], rowIter++);
}
createChart(descending,"Distribution on Key Messages",chartContainer);
}
function createChart(data,title,container){
var chart = new CanvasJS.Chart(container, {
animationEnabled: true,
title: {
text: title
},
data: [{
type: "pie",
startAngle: 240,
yValueFormatString: "",
indexLabel: "{label} '('{y}')'",
dataPoints: data
}]
});
chart.render();
}
function addRow(tblName, colData, rowNum){
var table = document.getElementById(tblName);
var tableRow = table.insertRow(rowNum);
for (var index in colData){
var cell = tableRow.insertCell(index);
cell.innerHTML = colData[index];
}
}
이 해답으로
를 장착 기대한다. _sundBore (list, iteratee, [context]) 문서를 보자. –
위의 형식으로 배치했다. 하지만 html로 보여주기 위해 내림차순을 사용하면 작동하지 않습니다. 위의 수정 된 코드를 찾으십시오. 그것은 [6,6,7,6]과 같은 데이터를 보여줍니다. –