Google Charts - Diff Bar Chart

You are Here:

How to Draw a Diff Bar Chart?

In this example, we will draw a diff bar chart. Please hover the bars in the above chart to view particular details.


HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src=""></script> <style> #myDrawChart{ display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column; align-items:center; margin:20px 0; } #myDrawChart > span{ width:450px; height:300px; } </style> </head> <body> <div id="myDrawChart"> <span id='barchart_before'></span> <span id='barchart_after'></span> <span id='barchart_diff'></span> </div> <script> google.charts.load('current', {packages:['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var oldData = google.visualization.arrayToDataTable([ ['Name', 'Popularity'], ['Alex', 200], ['Blake', 4100], ['Charlie', 2700], ['Jade', 7200] ]); var newData = google.visualization.arrayToDataTable([ ['Name', 'Popularity'], ['Alex', 300], ['Blake', 650], ['Charlie', 1400], ['Jade', 5500] ]); var barChartBefore = new google.visualization.BarChart(document.getElementById('barchart_before')); var barChartAfter = new google.visualization.BarChart(document.getElementById('barchart_after')); var barChartDiff = new google.visualization.BarChart(document.getElementById('barchart_diff')); var options1 = { title:'Social Media Popularity 2019', titleTextStyle: { fontSize: 17, color: '#206020' }, legend: { position: 'top' }, }; var options2 = { title:'Social Media Popularity 2020', titleTextStyle: { fontSize: 17, color: '#5c5c3d' }, legend: { position: 'top' }, }; var options3 = { title:'Social Media Popularity 2019 vs 2020', titleTextStyle: { fontSize: 17, color: '#993300' }, legend: { position: 'top' }, }; barChartBefore.draw(oldData, options1); barChartAfter.draw(newData, options2); var diffData = barChartDiff.computeDiff(oldData, newData); barChartDiff.draw(diffData, options3); } </script> </body> </html>


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.

Share this Page

Meet the Author