Skip to content

Instantly share code, notes, and snippets.

@moshfeu
Last active September 25, 2020 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moshfeu/7fcf293af3e4b6b2172a3d0082a21834 to your computer and use it in GitHub Desktop.
Save moshfeu/7fcf293af3e4b6b2172a3d0082a21834 to your computer and use it in GitHub Desktop.
Corvid Analytics iframe's code
<!DOCTYPE html>
<html>
<body>
<script
type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"
></script>
<div id="chart_div"></div>
<siv id="loading">Loading...</siv>
<script>
// Initiate google charts
google.charts.load('current', { packages: ['corechart', 'line'] });
google.charts.setOnLoadCallback(init);
function onEvent(details) {
const data = new google.visualization.DataTable();
data.addColumn('date', 'day');
data.addColumn('number', 'Page Views');
data.addRows([...details]);
const options = {
pointSize: 5,
hAxis: {
title: 'Time',
format: 'dd/MM/yy',
},
vAxis: {
title: 'Popularity',
},
};
const chart = new google.visualization.LineChart(
document.getElementById('chart_div')
);
chart.draw(data, options);
}
function init() {
// Listen to messages from the page
window.addEventListener('message', ({ data: { type, data } }) => {
if (type === 'graph') {
onEvent(data);
document.querySelector('#loading').style.display = 'none';
}
});
}
// Tell the page the iframe's ready
window.parent.postMessage({ type: 'ready' }, '*');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment