我正在学习 angular-chart-js 的阶段。我正在尝试使用 angular-chart.js 来绘制饼图。但是我无法找到一种在饼图上显示标签(而不是工具提示)的方法,这些标签描述了每个数据切片。
这是我如何做到的:
angular.module('App').controller('Controller', ['$scope', '$http', '$location', '$window', '$routeParams',
function($scope, $http, $location, $window) {
var diskDataJson = {
"data": [80, 12],
"labels": [Used space, Free Space],
"colours": ['#9AB6F0', '#C2D3F6']
};
$scope.pieDiskData = json;
}
]);Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<table border="0" width="100%">
<tr>
<td style="border-left: 1px solid #0099CC" width="25%">
<center><span><label ng-bind-html="'load.static.dashboard.system.DUSAGE' | translate"/></span>
</center>
<canvas id="pie33" class="chart chart-pie chart-xs ng-isolate-scope" height="120" width="240" data="pieDiskData.data" labels="pieDiskData.labels" colours="pieDiskData.colours" legend="true"></canvas>
</td>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
我正在测试骨干视图,它具有以下功能:
attachSelect: function(id, route) {
console.log(id);
console.log(route);
this.$(id).select2({
ajax: {
url: route,
dataType: 'json',
results: function(data) {
var results = _.map(data, function(item) {
return {
id: item.id,
text: item.title
};
});
return {
results: results
};
},
cache: true
}
});
}
Run Code Online (Sandbox Code Playgroud)
我需要重写(模拟)这个功能,看起来像:
attachSelect: function(id, route) {
console.log(id);
console.log(route);
}
Run Code Online (Sandbox Code Playgroud)
怎么做 ?
我有一个包含JSON任务数组的文件:
目前该文件包含:
[
{"task":"hey", "checked":"0", "data1":"", "data2":"", "data3":""},
{"task":"there", "checked":"0", "data1":"jiojoi", "data2":"", "data3":""}
]
Run Code Online (Sandbox Code Playgroud)
我想隔离一个signle任务,所以我使用以下代码:
var taskExp = new RegExp('{"task":"' + taskName + '",.*"}', '');
// Get the task
var task = taskExp.exec(text);
Run Code Online (Sandbox Code Playgroud)
在这种特定情况下,如果taskName = "hey",它返回整个字符串.(2个任务).
如果taskName = "there",没关系.
为什么?提前致谢.
javascript ×3
angularjs ×1
backbone.js ×1
chart.js ×1
java ×1
json ×1
map ×1
mocha.js ×1
regex ×1
sinon ×1