8
A
回答
1
在圖表JS documentation中,在動畫完成使用時,您可以運行功能onAnimationComplete : function(){}
小提琴定義
你HTML文件也許這樣
<canvas id="my_chart"></canvas>
然後你的js文件可能看起來像這樣
fillColor: "#79D1CF",
strokeColor: "#79D1CF",
data: [60, 80, 81, 56, 55, 40]
var ctx = document.getElementById("myChart1").getContext("2d");
var myLine = new Chart(ctx).Line(chartData, {
showTooltips: false,
onAnimationComplete: function() {
//Your other ChartJs features defined here
var ctx = this.chart.ctx;
ctx.font = //your font
ctx.fillStyle = //your text color
ctx.textAlign = "center";
ctx.textBaseline = "bottom";
this.datasets.forEach(function (dataset) {
dataset.points.forEach(function (points) {
ctx.fillText(points.value, points.x, points.y - 10);//You can change the x and y position of the text as per your requirement
});
})
}
});
2
以下答案僅適用於Chart.js v2。
如果您想要v1解決方案,請選擇pritishvaidya's。
您想使用的圖表選項animation
屬性:
options : {
animation: {
duration: 500,
onComplete: function() {
// The code here will be executed at the end of the animation
// (after 500ms here)
// You can get the canvas context using the following :
var ctx = this.chart.ctx;
// `this` being the chart instance
}
}
}
現在要添加它上面的點,這可以用數據來完成的價值模型,您可以在數據集屬性中找到:
onComplete: function() {
// You get the canvas context, to help you writing what you want
var ctx = this.chart.ctx;
// Here you set the context with what you need (font, size, color ...)
ctx.font = Chart.helpers.fontString(Chart.defaults.global.defaultFontFamily, 'normal', Chart.defaults.global.defaultFontFamily);
ctx.textAlign = 'center';
ctx.fillStyle = 'black';
// For every dataset ...
this.data.datasets.forEach(function(dataset) {
// For every data in the dataset ...
for (var i = 0; i < dataset.data.length; i++) {
// We get its model
var model = dataset._meta[0].data[i]._model;
// And write the data above it
ctx.fillText(dataset.data[i], model.x, model.y - 2);
// You can edit the last two arguments according to what you need
}
});
}
遵循上面的代碼中,你可以找到on this jsFiddle結果:
相關問題
- 1. 雷分頁標籤引導
- 2. ChartJS onclick填充區域(雷達圖表)
- 3. 可搜索標籤文本Chartjs
- 4. chart.js更改雷達圖標籤大小
- 5. 使用ChartJS的EJS標籤?
- 6. Chartjs雷達 - 如何修改灰色網格線?
- 7. 移動點到ChartJS中的點擊點(雷達圖)
- 8. 如何使用ChartJS雷達繪製閃亮
- 9. Chartjs v2 xAxes標籤與標尺重疊標籤
- 10. Excel VSTO C# - 格式雷達圖表類別和軸標籤
- 11. 雷達圖外圍設備標籤截止
- 12. chart.js之雷達圖如何刪除外層標籤
- 13. Chart.js2雷達,如何配置標籤填充/間距?
- 14. 編輯標籤和軸限制的雷達圖表
- 15. z標籤上的索引
- 16. 創建標籤索引Django
- 17. Facelets重複標籤索引
- 18. mysql標籤表索引
- 19. Places API雷達搜索破解
- 20. ChartJS AJAX加載標籤和數據
- 21. chartjs - 編輯或刪除標籤
- 22. 點擊每個標籤onload ChartJS
- 23. Chartjs 2.5.0 - >圖表下方的標籤
- 24. Chartjs X軸標籤和刻度格式
- 25. ChartJS - 底部的標籤顯示垂直
- 26. 動畫像雷達目標C
- 27. Javascript和表達式引擎標籤
- 28. 檢索標籤的正則表達式
- 29. Amcharts雷達圖表
- 30. 新AMP HTML標籤和索引的搜索引擎
感謝您的回答,但它不適合我,我用圖表的2.2.0版本中運行.js,但我在[thread](http://stackoverflow.com/a/37550150/5962228)中找到了你提到的 – Zuri
的解決方案,抱歉不知道你的圖表版本,問題也在這裏解決https:// github .com/chartjs/Chart.js/pull/1775 –
如果我的回答滿足你的問題,那麼我相信我值得這個賞金感謝,因爲賞金不能去自我回答問題http://meta.stackexchange.com/questions/54998/我 - 剛剛榮獲-自己-A-賞金/ 97802#97802 –