我有一个基本的AmGraph:
graph = new AmCharts.AmGraph();
graph.lineThickness = 4;
graph.valueAxis = valueAxis;
graph.fillAlphas = 0;
graph.valueAxis = valueAxis;
graph.valueAxis.minimum = 0;
graph.title = "likes";
graph.labelText = " ";
graph.valueField = "likes_1";问题是,如果我使用自定义的numberFormatter函数,则balloonText不格式化值:
graph.numberFormatter = {precision: -1, decimalSeparator:",", thousandsSeparator:","};所以如果我用这个
graph.balloonText = "<b>got: [[likes_1]] </b>";工具提示如下:
"got: 1000"如何设置值的格式?如果我尝试使用javascript格式化它(Numeral.js):
graph.balloonText = "<script>numeral( [[likes_1]] ).format("0,0") </script>";在构建页面时,通配符没有被替换为实际值(而是在图表上悬停?),所以我只得到:
Uncaught ReferenceError: likes_32 is not defined我该怎么办?
发布于 2016-07-21 10:23:17
(首先,我强烈建议使用更新的图表初始化方式!(请看这里。)
您可以使用balloonText代替balloonFunction,这允许您用JavaScript更改文本。在里面,你可以根据你的意愿格式化数字。
我使用演示格式化程序编写了一个AmCharts.formatNumber。
return AmCharts.formatNumber(graphDataItem.values.value, {
precision: -1,
decimalSeparator: '.',
thousandsSeparator: ','
}, -1);不过,您仍然可以在其中使用Numeral.js (在我看来,它的语法似乎更直接一些)。
return numeral(graphDataItem.values.value).format("0,0");https://stackoverflow.com/questions/38476886
复制相似问题