Google Charts - Material Bar Chart
You are Here:
How to Draw a Material Bar Chart?
Please wait google chart is loading...
In this example, we will draw a material bar chart. Please hover the bars in the above chart to view particular details.
Example
HTML Online Editor
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
<div id="point">
</div>
<script>
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Month', 'Baked', 'Sold', 'Unsold'],
['Jan', 750, 700, 50],
['Feb', 800, 700, 100],
['Mar', 600, 400, 200],
['Apr', 1000, 850, 150]
]);
var options = {
chart: {
title: 'Black Forest Cake',
subtitle: 'Cakes Baked, Sold and Unsold: Jan 19 - Apr 19',
},
bars: 'horizontal', // Required for Material Bar Charts.
hAxis: {
format: 'decimal'
},
height: 400,
colors: ['#1b9e77', '#d95f02', '#7570b3']
};
var chart = new google.charts.Bar(document.getElementById('point'));
chart.draw(data, google.charts.Bar.convertOptions(options));
var btns = document.getElementById('btn-group');
btns.onclick = function (e) {
if (e.target.tagName === 'BUTTON') {
options.hAxis.format = e.target.id === 'none' ? '' : e.target.id;
chart.draw(data, google.charts.Bar.convertOptions(options));
}
}
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 98% of Google Charts Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in Google Charts.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.