【发布时间】:2012-12-31 09:55:05
【问题描述】:
能否请我帮忙格式化 Y 轴上带有 '%' 符号的字符串。
这是'$'的代码:
tickOptions: {formatString: '$%d'}
如何格式化字符串以使用“%”符号,因为“%”符号用作“关键字”?
【问题讨论】:
标签: javascript jqplot axis format-string
能否请我帮忙格式化 Y 轴上带有 '%' 符号的字符串。
这是'$'的代码:
tickOptions: {formatString: '$%d'}
如何格式化字符串以使用“%”符号,因为“%”符号用作“关键字”?
【问题讨论】:
标签: javascript jqplot axis format-string
试试这样的:
tickFormatter = function (format, val) {
return val+"%";
}
并将此选项添加到情节中:
axes: {
yaxis: {
tickOptions: {
formatter: tickFormatter
}
}
【讨论】:
要写一个 '%' 符号,你必须把它加倍:
axes:
{yaxis:
{tickOptions:
{formatString: '%%%d'}
}
}
如果您的值为 10,%%%d 将写入 '%10'。
同样,如果您的值再次为 10,%d%% 将写入 '10%'。
因此,您只需将 '$' 符号替换为 '%%'。
安东尼。
【讨论】: