Javascript 如何在Chartist.JS中向标签添加逗号
我得到了以下图表: 我想在Y标签上添加逗号,但似乎没有任何效果。我尝试了社区的一系列答案,但没有任何改变。也许是因为版本不同?我的完整图表代码如下:Javascript 如何在Chartist.JS中向标签添加逗号,javascript,chartist.js,Javascript,Chartist.js,我得到了以下图表: 我想在Y标签上添加逗号,但似乎没有任何效果。我尝试了社区的一系列答案,但没有任何改变。也许是因为版本不同?我的完整图表代码如下: <div class="ct-chart ct-major-eleventh graph"></div> <script> new Chartist.Line('.ct-chart', { labels: {{ chart_labels }}, series: [{{ char
<div class="ct-chart ct-major-eleventh graph"></div>
<script>
new Chartist.Line('.ct-chart', {
labels: {{ chart_labels }},
series: [{{ chart_values }}, {{ chart_values }} ]
}, {
low: {{ chart_low }},
showArea: true,
axisX: {
labelInterpolationFnc: function skipLabels(value, index) {
return index % 3 === 0 ? value : null;
}
},
ticks: {
beginAtZero: true,
callback: function(label, index, labels) {
return Intl.NumberFormat('hi', { style: 'currency', currency: 'USD', minimumFractionDigits: 2 } )
.format(label).replace(/^(\D+)/, '$1 ');
},
}
});
</script>
新图表列表线(“.ct图表”{
标签:{{chart_labels}},
系列:[{{chart\u values},{{{chart\u values}]
}, {
低:{{chart_low}},
展区:没错,
axisX:{
labelInterpolationFnc:函数SkipLabel(值、索引){
返回索引%3==0?值:null;
}
},
滴答声:{
贝吉纳泽罗:是的,
回调:函数(标签、索引、标签){
return Intl.NumberFormat('hi',{style:'currency',currency:'USD',minimumFractionDigits:2})
。格式(标签)。替换(/^(\D+/,“$1”);
},
}
});
在脚本部分包含此功能:
Number.prototype.format = function (n, x) {
var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\.' : '$') + ')';
return this.toFixed(Math.max(0, ~~n)).replace(new RegExp(re, 'g'), '$&,');
};
然后,在axisY部分中,包括以下内容:
labelInterpolationFnc: function (value) {
var temp = Number(value).format(0);
return temp;
},
格式(0)
设置小数位。我也在同一条船上!然而,我的问题涉及x轴上的日期。如果我在初始数据中添加一个逗号,则ChartList将其视为分隔符,而不管我将其括在单引号还是双引号中,图形都会变得一团糟。回调似乎也为我做了下蹲(因为它根本不改变数据)。我想如果有办法改变使用的定界符,那就行了,但是我找不到任何与定界符和图表相关的东西。我在ChartList github问题队列中添加了一个问题: