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.