Javascript 如何在charts.js的饼图工具提示中添加千位分隔符
我需要在饼图工具提示中添加千个分隔符,我曾尝试添加此分隔符Javascript 如何在charts.js的饼图工具提示中添加千位分隔符,javascript,chart.js,Javascript,Chart.js,我需要在饼图工具提示中添加千个分隔符,我曾尝试添加此分隔符 MultitoolTiptTemplate:function(label){return label.datasetLabel+':'+label.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g,“.”;} 但它不起作用。 这是我的完整代码: var pieChartCanvas = $('#pieChart').get(0).getContext('2d') var
MultitoolTiptTemplate:function(label){return label.datasetLabel+':'+label.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g,“.”;}
但它不起作用。
这是我的完整代码:
var pieChartCanvas = $('#pieChart').get(0).getContext('2d')
var pieChart = new Chart(pieChartCanvas)
var PieData = <?php echo json_encode($pasar2); ?>;
var pieOptions = {
multiTooltipTemplate : function(label){return label.datasetLabel + ': ' + label.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");},
//Boolean - Whether we should show a stroke on each segment
segmentShowStroke : true,
//String - The colour of each segment stroke
segmentStrokeColor : '#fff',
//Number - The width of each segment stroke
segmentStrokeWidth : 2,
//Number - The percentage of the chart that we cut out of the middle
percentageInnerCutout: 10, // This is 0 for Pie charts
//Number - Amount of animation steps
animationSteps : 100,
//String - Animation easing effect
animationEasing : 'easeOutBounce',
//Boolean - Whether we animate the rotation of the Doughnut
animateRotate : true,
//Boolean - Whether we animate scaling the Doughnut from the centre
animateScale : false,
//Boolean - whether to make the chart responsive to window resizing
responsive : true,
// Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container
maintainAspectRatio : true,
//String - A legend template
legendTemplate : '<ul class="<%=name.toLowerCase()%>-legend"><% for (var i=0; i<segments.length; i++){%><li><span style="background-color:<%=segments[i].fillColor%>"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>'
}
//Create pie or douhnut chart
// You can switch between pie and douhnut using the method below.
pieChart.Doughnut(PieData, pieOptions)
var pieChartCanvas=$('#pieChart').get(0.getContext('2d'))
var pieChart=新图表(pieChartCanvas)
var PieData=;
变量选项={
MultitoolTiptTemplate:function(label){return label.datasetLabel+':'+label.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g,“.”;},
//布尔-我们是否应该在每个线段上显示笔划
这是真的,
//字符串-每段笔划的颜色
segmentStrokeColor:“#fff”,
//数字-每个线段笔划的宽度
分段行程宽度:2,
//数字-我们从中间剪下的图表百分比
percentageInnerCutout:10,//对于饼图,这是0
//Number-动画步数
动画步骤:100,
//字符串动画效果
动画设置:“easeOutBounce”,
//布尔-是否设置圆环旋转的动画
动画片:对,
//布尔值-是否设置从中心缩放圆环的动画
动画缩放:错误,
//布尔值-是否使图表响应窗口大小调整
回答:是的,
//布尔值-响应时是否保持起始纵横比,如果设置为false,将占用整个容器
维护Aspectratio:是的,
//字符串-图例模板
legendTemplate:“
”
}
//创建饼图或双圆图
//您可以使用下面的方法在pie和douhnut之间切换。
pieChart.Doughnut(PieData,pieOptions)
试试这个:
function(label){
//Assuming the label.value is a number
let amount = label.value.toFixed(2);
let tooltipLabel = label.datasetLabel + ': ' + amount.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
return tooltipLabel;
}
试试这个:
function(label){
//Assuming the label.value is a number
let amount = label.value.toFixed(2);
let tooltipLabel = label.datasetLabel + ': ' + amount.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
return tooltipLabel;
}