I have managed to connect the graph to DB following the article here: https://www.vorbly.com/Vorbly-Code/WIX-IFRAME-GRAPHS-%26-CHARTS-WITH-FILTERS
I need it to display info only related to the member currently logged in. So in the DB collection I have assigned to each member a unique account number.
The issue is that the chart displays all the information in the database for all users.
Any ideas on how to filter the chart to show only lets say “owner” information?
For any adjustment that can be made via code please see code below:
Thanks
import wixData from 'wix-data';
import {monthSort} from 'public/months';
$w.onReady(function () {
$w("#table1").columns = [
{
"id": "col1",
"dataPath": "month",
"label": "Month",
"type": "string"
},
{
"id": "col2",
"dataPath": "amount",
"label": "Number of Trades",
"type": "number"
},
{
"id": "col3",
"dataPath": "total",
"label": "Total Repay",
"visible": true,
"type": "string"
}
];
wixData.query("Expenses")
.ascending("month")
.limit(1000) // Max limit of 1,000 //
.contains("fxrAccount", $w("#dropdown1").value)
.find()
.then( (result) => {
const months = result.items.map(x => x.month)
.filter((obj, index, self) => index === self.indexOf(obj))
.sort(monthSort);
const aggregated = months.map(x => {
return {
month: x,
total: result.items.filter(obj => obj.month === x)
.map(z => z.amount)
.reduce((sum, current) => sum + current)
};
});
$w("#table1").rows = aggregated;
let tableArr = [];
for ( var i = 0; i < $w("#table1").rows.length; i++ ) {
tableArr.push (
$w("#table1").rows[i]["total"]
)
}
$w("#html1").postMessage(tableArr);
});
});
export function dropdown1_change(event, $w) {
$w("#html1").show();
let product = $w("#dropdown1").value;
$w("#table1").columns = [
{
"id": "col1",
"dataPath": "month",
"label": "Month",
"type": "string"
},
{
"id": "col2",
"dataPath": "amount",
"label": "Number of Trades",
"type": "number"
},
{
"id": "col3",
"dataPath": "total",
"label": "Total Repay",
"visible": true,
"type": "string"
}
];
wixData.query("Expenses")
.ascending("month")
.eq("type", product)
.limit(1000)
.contains("fxrAccount", $w("#dropdown1").value)
.find()
.then( (result) => {
const months = result.items.map(x => x.month)
.filter((obj, index, self) => index === self.indexOf(obj))
.sort(monthSort);
const aggregated = months.map(x => {
return {
month: x,
total: result.items.filter(obj => obj.month === x)
.map(z => z.amount)
.reduce((sum, current) => sum + current)
};
});
$w("#table1").rows = aggregated;
let tableArr = [];
for ( var i = 0; i < $w("#table1").rows.length; i++ ) {
tableArr.push (
$w("#table1").rows[i]["total"]
)
}
console.log(tableArr);
$w("#html1").postMessage(tableArr);
});
}