我在角度应用程序中使用nvd3图表。我收到以下格式的标签
["14:49", "14:58", "14:57", "14:56", "14:55", "14:54", "14:53", "14:52", "14:51"]
我必须根据时间对它们进行排序。这是我的代码
var hourMin = new Date($scope.items[i].timestamp);
$scope.labels[i] = hourMin.getHours() + ":" + hourMin.getMinutes();
HTML:
<canvas id="line" class="chart chart-line" chart-data="data"
chart-labels="labels" chart-legend="true" chart-series="series"
chart-click="onClick" >
</canvas>
我已经尝试了orderBy
,但它无效。帮助我。
答案 0 :(得分:1)
使用这个.......
<script>
angular.module('app', [])
.controller('test', ['$scope', function($scope){
var test = ["14:49", "14:58", "14:57", "14:56", "14:55", "14:54", "14:53", "14:52", "14:51"];
test.sort(function (a, b) {
return new Date('1970/01/01 ' + a) - new Date('1970/01/01 ' + b);
});
console.log(test);
}])
</script>