如何在 AmChart5 中将图像添加到标签?
How do I add an image to a label in AmChart5?
在数据中我有一个 am5.Picture 对象
icon = am5.Picture.new(root, {
height: 28,
src: src
});
图片适合文本,没有插入旁边
这个也不行
series.labels.template.set("text", "{icon} {name}") // return only name
series.labels.values.forEach((label, index) => {
if (label.dataItem.dataContext.icon) {
let container = am5.Container.new(root, {
layout: root.horizontalLayout
})
container.children.push(label.dataItem.dataContext.icon)
container.children.push(
am5.Label.new(root, {
text: label.dataItem.dataContext.name,
fontSize: 10,
textAlign: "left",
centerY: am5.percent(50),
paddingLeft: 5,
})
)
label.children.clear()
label.children.push(container)
} else {
label.setAll({
fontSize: 10,
fontWeight: "300",
textAlign: "left",
maxWidth: 260,
oversizedBehavior: "wrap",
text: "{name}"
})
}
})
在数据中我有一个 am5.Picture 对象
icon = am5.Picture.new(root, {
height: 28,
src: src
});
图片适合文本,没有插入旁边
这个也不行
series.labels.template.set("text", "{icon} {name}") // return only name
series.labels.values.forEach((label, index) => {
if (label.dataItem.dataContext.icon) {
let container = am5.Container.new(root, {
layout: root.horizontalLayout
})
container.children.push(label.dataItem.dataContext.icon)
container.children.push(
am5.Label.new(root, {
text: label.dataItem.dataContext.name,
fontSize: 10,
textAlign: "left",
centerY: am5.percent(50),
paddingLeft: 5,
})
)
label.children.clear()
label.children.push(container)
} else {
label.setAll({
fontSize: 10,
fontWeight: "300",
textAlign: "left",
maxWidth: 260,
oversizedBehavior: "wrap",
text: "{name}"
})
}
})