플러그인을 만들어이 기능을 사용할 수 있습니다. 나는이 순간에 vue 빌드 작업을하고 있지만 최대한 많이 당신을 위해 그것을 시도했습니다.
템플릿
template: `
<base-chart
class="chart"
[datasets]="datasets"
[labels]="labels"
[options]="options"
[chartType]="'line'"
[plugin]="dataLabelPlugin">
</base-chart>
`
JS는 JS 각 애니메이션 후 숫자를 그리는 플러그인을 정의
private options = {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
plugins: [{
afterDatasetsDraw: this.dataLabelPlugin
}]
};
플러그인에 추가 할 수 있습니다. 컨텍스트에 따라 수정중인 차트를 전달해야 할 수도 있습니다.
private dataLabelPlugin = function(chart, easing) {
// To only draw at the end of animation, check for easing === 1
const ctx = chart.ctx;
const fontSize = 12;
const fontStyle = 'normal';
const fontFamily = 'open sans';
const padding = 5;
chart.data.datasets.forEach((dataset, key) => {
let meta = chart.getDatasetMeta(key);
if (!meta.hidden) {
meta.data.forEach((element, index) => {
let position = element.tooltipPosition();
// Just naively convert to string for now
let dataString = dataset.data[index].toString();
ctx.fillStyle = '#676a6c';
ctx.font = Chart.helpers.fontString(fontSize, fontStyle, fontFamily);
// Make sure alignment settings are correct
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(dataString, position.x, position.y - (fontSize/2) - padding);
});
}
});
};
이 작업을 수행하는 경우 알려 주시면이 답변을보다 정확하게 수정할 수 있습니다.