1 回答
TA贡献1860条经验 获得超8个赞
您可以尝试在画布上绘制文本(我没有检查过):
function saveAsImage(chartColumnID) {
html2canvas($('#' + chartColumnID), {
onrendered: function(canvas) {
// ----------------------------- here we draw text:
const fontHeight = 14;
const text = String(chartColumnID);
const ctx = canvas.getContext("2d");
ctx.font = fontHeight + "px Arial";
ctx.textAlign = "left";
ctx.fillStyle = "red"; // text color
ctx.fillText(text, 0, fontHeight);
// ------------------------------ your code as ususal:
var a = document.createElement('a');
a.href = canvas.toDataURL("image/png");
a.download = chartColumnID;
a.click();
}
});
};
它在画布上的外观示例:
var canvas = document.getElementById("c");
var chartColumnID = (Math.random() * 1000 + 1) | 0;
canvas.width = 100;
canvas.height = 100;
const fontHeight = 14;
const text = String(chartColumnID);
const ctx = canvas.getContext("2d");
ctx.font = fontHeight + "px Arial";
ctx.textAlign = "left";
ctx.fillStyle = "red"; // text color
ctx.fillText(text, 0, fontHeight);
canvas { border: 1px solid }
<canvas id="c" />
添加回答
举报