我正在使用
但是當我下載它時,由于圖表不可讀,一些 css 丟失了

下面是我用來下載的代碼
var saveSvgToPng = document.getElementById("download-button");
saveSvgToPng.onclick = function () {
saveSvgAsPng(d3.select('svg').node(), "dia.png", {
scale: 2,
});
};
我該如何解決這個問題。
提前致謝!
uj5u.com熱心網友回復:
對于所有面臨這個問題的人。正如@RobertLongson 在評論中所建議的那樣,當我切換到行內 css 而不是外部 css 時它起作用了。
導致問題的帶有外部 css 的代碼
nodes
.append("text")
.attr("font-size", "12px")
.attr("text-anchor", "middle")
.text(function (d) {
return `${d.data.name}`
})
外部CSS
text {
text-shadow: -1px -1px 3px white, -1px 1px 3px white, 1px -1px 3px white,
1px 1px 3px white;
cursor: pointer;
font-family: "Playfair Display", serif;
}
帶有行內 css 的代碼,解決了問題
nodes
.append("text")
.attr("font-size", "12px")
.attr("text-anchor", "middle")
.style(
"text-shadow",
`-1px -1px 3px white, -1px 1px 3px white, 1px -1px 3px white,
1px 1px 3px white`
)
.style("cursor", "pointer")
.style("font-family", `"Playfair Display", serif`)
.text(function (d) {
return `${d.data.name}`
})
希望這對某人有幫助!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/465887.html
標籤:javascript jQuery css svg d3.js
