Assistance with working with data collection

I am trying to write a code to pull data from a data collection to be displayed as a chart.

Below is the code:
import wixData from ‘wix-data’;

$w.onReady(function () {
$w(‘#scatterhtml’).onMessage((event) => {
let received = event.data;
$w(‘#dataText’).text = received;
console.log(received);
})
refreshData();
});

function refreshData () {
wixData.query(“SalaryScatter”)
.ascending(“currentSalary”)
.find()
.then((results) => {
if (results.items.length > 0) {
var rawData = results.items;
console.log(rawData);
var arrData = JSON.stringify(rawData)
var data = arrData;
console.log(data);
$w(‘#scatterhtml’).postMessage(data);
}
})
}

Any suggestions is greatly appreciated!

Wix already have a tutorial for a custom chart.
https://www.wix.com/corvid/example/create-a-custom-chart

Hope this is helpful to you.

Thank you for that reference. I have used that to build the initial charts. Do you know of a way to pull the data from a wix data base rather then from a fixed data array as in the example?

You can use a standard database query to retrieve your data, and then pass them as a data arrary as in the example. See the content examples for examples on retrieving data from a database collection.