I have a pie chart that I want to only show data related to the logged-in user.
Is there a way to filter a chart so that only the logged-in user can see their data?
I have a pie chart that I want to only show data related to the logged-in user.
Is there a way to filter a chart so that only the logged-in user can see their data?
Hi Makalya,
Yes, you can use this hook to filter the chart data. In my snippet, I am getting the logged-in user’s data and filtering the chart data by their email.
Please add this to the Developer options > This screen > JS.
Fliplet.Hooks.on('beforeChartQuery', function(data) {
return Fliplet.User.getCachedSession().then(function(session) {
var user = _.get(session, 'entries.dataSource.data');
data.config.dataSourceQuery.query = {
where: {
//Change Email below to the column in the chart data set containing the Emails of the users.
//Change user.Email to the column in the login data source containing the user's email.
Email: user.Email
}
};
});
});
Thanks,
Deb