Angular 图表获取和使用图表数据和标签值
Angular Chart Getting and Using Chart Data and Label Values
我正在做一个 angular 图表,它具有三个值和显示标签,当我单击图表时它必须显示我单击的标签。我正在尝试从点中获取值。
$scope.data = ["prospective","CallBacks","Closed"];
$scope.labels = ["4","2","3"];
$scope.onClick = function (points,evt) {
console.log("Points: "+JSON.stringify(points));
$scope.struct=JSON.stringify(points);
$scope.value=$scope.struct.label;
}
<canvas id="pieChart" class="chart chart-pie"
chart-data="data" chart-labels="labels" chart-legend="true" chart-click="onClick">
</canvas>
<span>{{value}}</span>
日志显示如下:
[{"value":4,"outerRadius":95.5,"innerRadius":0,"fillColor":"rgba(151,187,205,0.8)","highlightColor":"rgba(151,187,205,0.8)","showStroke":true,"strokeWidth":2,"strokeColor":"#fff","startAngle":4.71238898038469,"circumference":1.9332877868244882,"label":"Prospective","_saved":{"value":4,"outerRadius":95.5,"innerRadius":0,"fillColor":"rgba(151,187,205,1)","highlightColor":"rgba(151,187,205,0.8)","showStroke":true,"strokeWidth":2,"strokeColor":"#fff","startAngle":4.71238898038469,"circumference":0,"label":"Prospective"},"endAngle":6.645676767209178}]
我可以从日志中获取值,但在 $scope.value 中使用相同的值,标签显示为未定义。
感谢大家的支持,有 json 数组,当我给 $scope.value=$scope.struct[0].label 时,它似乎工作得很好..
我正在做一个 angular 图表,它具有三个值和显示标签,当我单击图表时它必须显示我单击的标签。我正在尝试从点中获取值。
$scope.data = ["prospective","CallBacks","Closed"];
$scope.labels = ["4","2","3"];
$scope.onClick = function (points,evt) {
console.log("Points: "+JSON.stringify(points));
$scope.struct=JSON.stringify(points);
$scope.value=$scope.struct.label;
}
<canvas id="pieChart" class="chart chart-pie"
chart-data="data" chart-labels="labels" chart-legend="true" chart-click="onClick">
</canvas>
<span>{{value}}</span>
日志显示如下:
[{"value":4,"outerRadius":95.5,"innerRadius":0,"fillColor":"rgba(151,187,205,0.8)","highlightColor":"rgba(151,187,205,0.8)","showStroke":true,"strokeWidth":2,"strokeColor":"#fff","startAngle":4.71238898038469,"circumference":1.9332877868244882,"label":"Prospective","_saved":{"value":4,"outerRadius":95.5,"innerRadius":0,"fillColor":"rgba(151,187,205,1)","highlightColor":"rgba(151,187,205,0.8)","showStroke":true,"strokeWidth":2,"strokeColor":"#fff","startAngle":4.71238898038469,"circumference":0,"label":"Prospective"},"endAngle":6.645676767209178}]
我可以从日志中获取值,但在 $scope.value 中使用相同的值,标签显示为未定义。
感谢大家的支持,有 json 数组,当我给 $scope.value=$scope.struct[0].label 时,它似乎工作得很好..