Running a Query and placing data in a Array for use in a Graph

Hi,

Hoping someone can give me a hand. Have got dataset with a few fields, but i’m interested in two fields in particular which contain a date and a number. I want to run a query, and have the results from that built into an array, ignoring all the other fields from the query, and maped so the date and number correspond to one another for use in a graph.

I’ve been following this example: https://medium.com/swlh/build-your-own-analytics-tool-on-corvid-by-wix-cd12ae76d291

I can get the date’s from my dataset to show up in the graph, but can’t workout how to get my numbers to appear or send them to the graph. Any help would be greatly appreciated.

const getDataPromise = wixData. query (‘attendance’). 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
// This sends the dates across correctly, but i’ve no idea how to get the values to send with it which is just a number?

const chartData = Object . entries (
_. groupBy (results. items ,(item) => item.date))
. map (([date,entities]) => [ new Date (date),entities. length ]);
// Post back to the page with the data
$w (‘#html1’). postMessage ({
type : ‘graph’,
data : chartData,
}