JSFiddle - React, Tailwind, and code Playground
by bbuntz
HTML
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
CSS
#chart_div {
width: 100%;
height: 700px;
}
JavaScript
google.charts.load('current', {
'packages': ['corechart', 'bar']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(
[
['Product Category', 'AbbVie', 'AstraZeneca', 'BMS', 'Bayer', 'BioNTech', 'GSK', 'Gilead', 'J&J', 'Merck & Co.', 'Moderna, Inc.', 'Novartis', 'Pfizer', 'Regeneron', 'Roche', 'Sanofi'],
['Oncology', 2356.0, 5642.0, 3450.0, 0.0, 0.0, 0.0, 177.0, 2956.0, 6271.0, 0.0, 2483.0, 2803.0, 210.0, 4539.273, 0.0],
['Immunology', 6813.0, 0.0, 927.0, 0.0, 0.0, 0.0, 0.0, 3246.0, 203.0, 0.0, 1272.0, 1043.0, 0.0, 1227.225, 2766.07],
['Infectious Diseases', 387.0, 0.0, 0.0, 0.0, 181.54, 4364.0, 3101.0, 0.0, 2458.0, 293.0, 0.0, 3392.0, 2.0, 0.0, 957.73],
['Cardiovascular', 0.0, 2167.0, 3204.0, 1133.55, 0.0, 0.0, 0.0, 609.0, 0.0, 0.0, 1516.0, 1821.0, 41.0, 0.0, 0.0],
['Neurology', 1885.0, 0.0, 0.0, 0.0, 0.0, 115.0, 0.0, 0.0, 0.0, 0.0, 489.0, 247.0, 0.0, 1637.7, 727.51]
]);
var options = {
width: '100%',
height: 700,
title: 'Revenues by Top 5 Product Categories (2023 Q2) - Broken Down by Company',
isStacked: true,
hAxis: {
title: 'Product Category'
},
vAxis: {
title: 'Revenues (in millions)'
},
legend: {
position: 'top',
maxLines: 3
},
bar: {
groupWidth: '75%'
},
isStacked: true
};
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(data, options);
}