Chart.js V2: Add prefix or suffix to tooltip label

前端 未结 6 1552
情书的邮戳
情书的邮戳 2020-12-04 16:03

In Chart.js V1.0, I would add tooltipTemplate: \"<%if (label){%><%=label %>: <%}%><%= \'€\' + value %>\" to add a euro symbol as prefix

6条回答
  •  独厮守ぢ
    2020-12-04 16:28

    In addition to iecs' answer, if you want to return the exact default text and add some more (like a € sign in your case), use following syntax :

    var ctx = $(chartCanvas);
    window.chartObject = new Chart(ctx, {
        type: 'bar',
        data: chartData,
        options: {            
            tooltips: {
                callbacks: {
                    label: function(tooltipItems, data) {
                        return data.datasets[tooltipItems.datasetIndex].label +': ' + tooltipItems.yLabel + ' €';
                    }
                }
    
            }
        }
    });
    

提交回复
热议问题