我正在使用谷歌条形图 https://developers.google.com/chart/interactive/docs/gallery/barchart .的标题存储在数据库中,其中一些包含撇号。标题中的那些撇号呈现为&39,例如“he's”--->“he&39s”
我希望撇号正常呈现。
我找到了几种解决方案,但到目前为止,没有一种解决方案适用于如此简单的任务。
有什么有效的解决方案吗?
更新:
这是正确呈现的,因为 I'm goooood
var chart = new google.visualization.ColumnChart(document.getElementById("my_div"));
chart.draw(data, {
title: "I'm goooood",
legend: {position: "none"},
});
但这 - 不是,它是 ---> 我很高兴
var chart = new google.visualization.ColumnChart(document.getElementById("my_div"));
chart.draw(data, {
title: "<%= get_value_from_db() %>",
legend: {position: "none"},
});"
在其他页面上,没有图表,只有文本,“<%= get_value_from_db() %>”得到正确呈现——我很好
。
最佳答案
我遇到了同样的问题,但只是 ' 和 "被渲染为“&39”或“&34”。
由于上述修复对我都不起作用,我依赖的一个快速但非常肮脏的解决方案是使用 string.replace 与素数 ( ′ ) 和双素数 ( ″ ) 符号 - 循环合理数量的次。
<%= varName.replace("\'",'′').replace("\"",'″ ') %>
此外,我认为此错误可能与 Google Charts 和 EJS 如何交互有关,因为 OP 和我都在使用它并遇到此问题。 (纯属猜测)
关于javascript - 防止 Google Charts 在图表标题中转义撇号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46646512/