<div class="relative">
<canvas class="w-full min-h-48" id="ChartMixed"></canvas>
</div>
<script>
// Convert HEX TO RGBA
function hexToRGBA(hex, opacity) {
if (hex != null) {
return 'rgba(' + (hex = hex.replace('#', '')).match(new RegExp('(.{' + hex.length/3 + '})', 'g')).map(function(l) { return parseInt(hex.length%2 ? l+l : l, 16) }).concat(isFinite(opacity) ? opacity : 1).join(',') + ')';
}
}
// Chart Mixed
const chart_mixed = document.getElementById("ChartMixed");
if ( chart_mixed != null) {
const ctbm = chart_mixed.getContext('2d');
const FinChart = new Chart(ctbm, {
type: 'scatter',
data: {
labels: [
'Nov','Dec','Jan','Feb','Mar','Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
],
datasets: [{
type: 'line',
label: 'Target Sales',
data: [64080,63080,72080,87080,85080,85080,83080,81080,85080,85080,85080,88080],
backgroundColor: [
hexToRGBA( '#6366f1', 0.8),
],
borderColor: hexToRGBA( '#6366f1', 0.8),
borderDash: [4, 4],
tooltip: {
callbacks: {
label: (Item) => (Item.formattedValue) + '$ Target'
}
}
},
{
type: 'bar',
label: 'Sales',
data: [76080, 62900, 82055, 94380, 93598, 84980, 77798, 70680, 84798, 92680, 95798, 98000],
fill: false,
backgroundColor: [
'#a855f7',
'#eab308',
'#a855f7',
'#a855f7',
'#a855f7',
'#eab308',
'#ec4899',
'#ec4899',
'#eab308',
'#a855f7',
'#a855f7',
'#a855f7'
],
borderColor: [
'#a855f7',
'#eab308',
'#a855f7',
'#a855f7',
'#a855f7',
'#eab308',
'#ec4899',
'#ec4899',
'#eab308',
'#a855f7',
'#a855f7',
'#a855f7'
],
barPercentage: 0.4,
borderWidth: 0,
tooltip: {
callbacks: {
label: (Item) => (Item.formattedValue) + '$ Sales'
}
}
}]
},
options: {
interaction: {
mode: 'index',
intersect: false,
},
animation: {
delay: 2000
},
scales: {
y: {
beginAtZero: true,
min: 0,
max: 120000,
grid: {
borderDash: [4, 4]
},
ticks: {
// Include % in the ticks
callback: function(value, index, ticks) {
return value + '$';
}
}
}
},
plugins: {
legend: {
display: false
}
}
}
})
}
</script>