Last active
September 25, 2020 22:28
-
-
Save moshfeu/b9d201de5806fde1f89e3267c33e41c5 to your computer and use it in GitHub Desktop.
Corvid Analytics page's code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wixData from 'wix-data'; | |
import _ from 'lodash'; | |
$w.onReady(function () { | |
const getDataPromise = wixData.query('views').find(); | |
// The iframe is ready | |
$w('#html1').onMessage(async ({ data }) => { | |
if (data.type === 'ready') { | |
const results = await getDataPromise; | |
// Group the rows by date and map it to DataTable format | |
const chartData = Object.entries( | |
_.groupBy(results.items, (item) => item._createdDate.toDateString()) | |
).map(([date, entities]) => [new Date(date), entities.length]); | |
// Post back to the page with the data | |
$w('#html1').postMessage({ | |
type: 'graph', | |
data: chartData, | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment