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
- 3. chart.js更改雷达图标签大小
- 4. 使用ChartJS的EJS标签?
- 5. ChartJS linechart编辑yAxis标签
- 6. Chartjs雷达 - 如何修改灰色网格线?
- 7. 移动点到ChartJS中的点击点(雷达图)
- 8. chartjs的雷达图始终保持填充
- 9. 如何使用ChartJS雷达绘制闪亮
- 10. Py2Neo标签索引
- 11. 正则表达式在标签索引上的搜索(密码)
- 12. Chartjs v2 xAxes标签与标尺重叠标签
- 13. Neo4j 2.0:索引与标签
- 14. Facelets重复标签索引
- 15. mysql标签表索引
- 16. z标签上的索引
- 17. 创建标签索引Django
- 18. 如何禁用Chart.js雷达图点标签
- 19. chart.js之雷达图如何删除外层标签
- 20. x轴标签自动换行高图中的雷达图表
- 21. 高图表标签我创造高图表雷达图和视
- 22. 如何更改asp.net雷达图中x轴标签的方向?
- 23. 雷达图外围设备标签截止
- 24. Chart.js2雷达,如何配置标签填充/间距?
- 25. Excel VSTO C# - 格式雷达图表类别和轴标签
- 26. 编辑标签和轴限制的雷达图表
- 27. ChartJS - 底部的标签显示垂直
- 28. 点击每个标签onload ChartJS
- 29. Chartjs 2.5.0 - >图表下方的标签
- 30. chartjs - 编辑或删除标签
感谢您的回答,但它不适合我,我用图表的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 –