admin 管理员组文章数量: 1086019
This is part of chart code. I am trying to show the image on the yaxis. My first problem is that the img.onload does not hit because It does not set the width and height. 2nd it just show [Object HTMLImageElement]
.
yAxes: [{
display: true,
scaleLabel: {
display: false,
},
ticks: {
min: 0,
max: MaxLength,
stepSize: 1,
callback: (value) => {
if (value !== 0) {
const img = new Image();
img.src = getimagePath(value);
img.onload = () => {
img.width = 4;
img.height = 4;
};
return img;
}
return ``;
},
},
gridLines: {
display: false,
}
}]
This is part of chart code. I am trying to show the image on the yaxis. My first problem is that the img.onload does not hit because It does not set the width and height. 2nd it just show [Object HTMLImageElement]
.
yAxes: [{
display: true,
scaleLabel: {
display: false,
},
ticks: {
min: 0,
max: MaxLength,
stepSize: 1,
callback: (value) => {
if (value !== 0) {
const img = new Image();
img.src = getimagePath(value);
img.onload = () => {
img.width = 4;
img.height = 4;
};
return img;
}
return ``;
},
},
gridLines: {
display: false,
}
}]
Share
Improve this question
edited Mar 27 at 10:00
Naren Murali
60k5 gold badges44 silver badges77 bronze badges
asked Mar 27 at 9:58
Muhammad NadeemMuhammad Nadeem
111 bronze badge
2
- Can you attach the observed and expected output? – Naveed Ahmed Commented Mar 27 at 10:02
- i can not attach the file yet. – Muhammad Nadeem Commented Mar 28 at 15:29
2 Answers
Reset to default 0yAxes: [{
display: true,
scaleLabel: { display: false },
ticks: {
min: 0,
max: MaxLength,
stepSize: 1,
callback: (value) => {
if (value !== 0) {
const imagePath = getimagePath(value);
return `<img src="${imagePath}" width="20" height="20" style="vertical-align: middle;" />`;
}
return ``;
}
},
gridLines: {
display: false,
}
}]
This will helps you
Please just set the property values without the onLoad
and return the image.
callback: (value) => {
if (value !== 0) {
const img = new Image();
img.src = getimagePath(value);
img.width = 4;
img.height = 4;
return img;
}
return '';
}
本文标签: angularjsChartJS to show image on yaxisStack Overflow
版权声明:本文标题:angularjs - ChartJS to show image on y-axis - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744098079a2533270.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论