visit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Dashboard</title>
<link rel="stylesheet" href="styles/styles.css">
<link href="//fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<script type="text/javascript" src="//www.gstatic.com/charts/loader.js"></script>
<script type="module" src="js/pieChart.js" defer></script>
<script type="module" src="js/barChart.js" defer></script>
<script type="module" src="js/lineChart.js" defer></script>
<script type="module" src="js/map.js" defer></script>
</head>
<body>
<header>
<span>Dashboard with google charts</span>
</header>
<section>
<div class="container">
<div class="row">
<div class="chart-widget">
<div class="widget-header">
<span>Company Performance</span>
</div>
<div class="chart">
<div id="bar-chart" style="width: 44vw; height: 400px;"></div>
</div>
</div>
<div class="chart-widget">
<div class="widget-header">
<span>Monthly performance for 2021 year</span>
</div>
<div class="chart">
<div id="line-chart" style="width: 44vw; height: 400px;"></div>
</div>
</div>
</div>
<div class="row">
<div class="chart-widget">
<div class="widget-header">
<span>Most popular products</span>
</div>
<div class="chart">
<div id="pie-chart" style="width: 34vw; height: 500px;"></div>
</div>
</div>
<div class="chart-widget">
<div class="widget-header">
<span>Map</span>
</div>
<div class="chart">
<div id="map" style="width: 54vw; height: 500px;"></div>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
<script type="text/javascript" src="//www.gstatic.com/charts/loader.js"></script>
const drawChart = () => {
var data = google.visualization.arrayToDataTable([
['Product', 'Sales'],
['TV', 9],
['Xbox', 3],
['Playstation', 3],
['Iphone', 6],
['MacBook', 3]
]);
var options = {
pieHole: 0.4,
};
// Here we have to pass an ID ov div where we want to append a chart.
var chart = new google.visualization.PieChart(document.getElementById('pie-chart'));
chart.draw(data, options);
}
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
Advantages
- Provides a big collection of charts; - Easy to use and implements;- Does not require deep knowledge of coding;Disadvantages
- Does not provide as much flexibility in customizing charts as other libraries do; - Some charts do not support a large amount of data;- Requires network connection;Wrapping up
Google charts are very easy to use and can provide a good choice of high-quality charts. They can be implemented even by a non-tech savvy person. It is a good solution in case there is a need to introduce a quick demo for the presentation of some demo app for end-user. But I believe for a bigger scale it is better to pick some other library, for example, D3.js. It provides enough flexibility in customizing the charts and can handle a huge amount of data. But the downside is that it is a bit more complicated to learn. Hope it was useful. More about another library you get from my previous articles on Hacker Noon or on Github!