I want to add a prefix to the tooltip and y-label in chartjs, but the problem is, when I put the <i class='fa fa-sampleicon'></i>
it is returned as string not as an html tag as you can see on the image
Here's my code:
<script>
$(document).ready(function(){
var lineLabel = <?php echo json_encode(array_reverse( $ch1_arrDate)); ?>;
var dataVal1 = <?php echo json_encode(array_reverse( $ch1_arrRevenue_conf)); ?>;
var dateFilter = <?php echo json_encode(array_reverse($ch1_arrDate2)); ?>;
var lineData = {
labels: lineLabel,
datasets: [
{
label: 'Confirmed Revenue',
backgroundColor: 'rgba(0,0,0,0.03)',
data: dataVal1,
borderColor: 'rgba(163,216,3,1)',
borderWidth:1,
},
]
};
var lineOptions = {
responsive: true,
maintainAspectRatio: true,
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
userCallback: function(value, index, values) {
return "<i class='fa fa-sampleicon'></i>"+addCommas(value);
}
}
}]
},
legend: {
display: true,
position: 'bottom'
},
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
return "<i class='fa fa-sampleicon'></i>"+addCommas(tooltipItem.yLabel);
}
}
}
}
var ctx = document.getElementById("chart1").getContext("2d");
if($(window).width()>748){
ctx.canvas.height = 160;
}
else{
ctx.canvas.height = 300;
}
var chartDisplay = new Chart(ctx, {
type: 'line',
data: lineData,
options: lineOptions
});
$("#chart1").click(
function(e){
var activeLines= chartDisplay.getElementsAtEvent(e);
var index = activeLines[0]["_index"];
window.open(
"dash_chartdeals.php?from=past&filter_date="+fixedEncodeURIComponent(dateFilter[index]),
'_blank'
)
});
$("#chart1").mouseenter(function(){
$("#chart1").css("cursor", "pointer");
});
});
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
</script>