[英]Draw constant line in angular-chart.js
I need to draw a constant line in my chart. 我需要在图表中画一条恒定线。 I'm using "angular-chart.js". 我正在使用“ angular-chart.js”。
This is my HTML section 这是我的HTML部分
<canvas
id="line"
class="chart chart-line"
chart-data="dataCPC"
chart-labels="labelsCPC"
chart-series="seriesCPC"
chart-options="optionsCPC"
chart-dataset-override="datasetOverride"
>
</canvas>
This is my angular code 这是我的角度代码
angular.module("app", ["chart.js"]).controller("LineCtrl", function
($scope, $http) {
var request = {
method: 'get',
url: 'asp/data.asp',
dataType: 'json',
contentType: "application/json"
};
$scope.arrLabelsACI = new Array;
$scope.arrDataACI = new Array;
$scope.dataACI = new Array;
$scope.labelsACI = new Array;
$http(request)
.success(function (jsonData) {
// LOOP THROUGH DATA IN THE JSON FILE.
angular.forEach(jsonData, function (item) {
//$scope.arrSeriesACI.push(item.TX_Total);
$scope.arrDataACI.push(item.AVG);
$scope.arrLabelsACI.push(item.HOUR);
});
// UPDATE SCOPE PROPERTIES FOR DATA.
$scope.dataACI.push($scope.arrDataACI.slice(0));
for (var i = 0; i < $scope.arrLabelsACI.length; i++) {
$scope.labelsACI.push($scope.arrLabelsACI[i]);
}
})
.error(function () {
});
$scope.datasetOverride = [{yAxisID: 'y-axis-1'}, {yAxisID: 'y-axis-2'}];
$scope.optionsACI = {
scales: {
yAxes: [
{
id: 'y-axis-1',
type: 'linear',
display: true,
position: 'left',
suggestedMin: 0,
ticks: {
min: 0
}
}
]
}
};
});
This is how it works right now 现在就是这样
https://i.screenshot.net/2e9pyf0 https://i.screenshot.net/2e9pyf0
This is what I need. 这就是我所需要的。
https://i.screenshot.net/30lg5sr https://i.screenshot.net/30lg5sr
Thanks a lot 非常感谢
finally I found a solution 终于我找到了解决方案
add chartjs-plugin-annotation.js 添加chartjs-plugin-annotation.js
<script src="js/chartjs-plugin-annotation.js"></script>
then this part and that's all. 然后这部分就够了。
annotation: {
annotations: [{
id: 'a-line-1',
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-1',
value: '5',
borderColor: 'red',
borderWidth: 1
}
This is the option code 这是选项代码
$scope.optionsACI = {
scales: {
yAxes: [
{
id: 'y-axis-1',
type: 'linear',
display: true,
position: 'left',
suggestedMin: 0,
ticks: {
min: 0
}
}
]
},
annotation: {
annotations: [{
id: 'a-line-1',
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-1',
value: '5',
borderColor: 'red',
borderWidth: 1
}
]
}
};
I hope this will help someone one day. 希望有一天能对某人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.