JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<br/><!-- Just so that JSFiddle's Result label doesn't overlap the Chart -->
<div id="chartContainer" style="height: 360px; width: 100%;"></div>
JavaScript
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title:{
text: "Google - Consolidated Quarterly Revenue",
fontFamily: "arial black",
fontColor: "#695A42"
},
axisX: {
interval: 1,
intervalType: "year",
labelAutoFit: false
},
axisY:{
valueFormatString:"$#0bn",
gridColor: "#B6B1A8",
tickColor: "#B6B1A8"
},
toolTip: {
shared: true,
content: toolTipContent
},
data: [{
type: "stackedColumn",
showInLegend: true,
color: "#696661",
name: "Q1",
dataPoints: [
{ y: 6.75, x: new Date(2010,0) },
]
},
{
type: "stackedColumn",
showInLegend: true,
name: "Q2",
color: "#EDCA93",
dataPoints: [
{ y: 6.82, x: new Date(2010,0) },
]
},
{
type: "stackedColumn",
showInLegend: true,
name: "Q3",
color: "#695A42",
dataPoints: [
{ y: 7.28, x: new Date(2010,0) },
]
},
{
type: "stackedColumn",
showInLegend: true,
name: "Q4",
color: "#B6B1A8",
dataPoints: [
{ y: 8.44, x: new Date(2010,0) },
]
}]
});
chart.render();
function toolTipContent(e) {
var str = "";
var total = 0;
var str2, str3;
for (var i = 0; i < e.entries.length; i++){
var str1 = "<span style= \"color:"+e.entries[i].dataSeries.color + "\"> "+e.entries[i].dataSeries.name+"</span>: $<strong>"+e.entries[i].dataPoint.y+"</strong>bn<br/>";
total = e.entries[i].dataPoint.y + total;
str = str.concat(str1);
}
str2 = "<span style = \"color:DodgerBlue;\"><strong>"+(e.entries[0].dataPoint.x).getFullYear()+"</strong></span><br/>";
total = Math.round(total * 100) / 100;
str3 = "<span style = \"color:Tomato\">Total:</span><strong> $"+total+"</strong>bn<br/>";
return (str2.concat(str)).concat(str3);
}