Hi,
How can I use a custom SQL query with a Feature Service data source in Experience Builder to dynamically filter data shown in a Chart widget based on user input?
Solved! Go to Solution.
To filter data in your Experience Builder chart:
const textBox = app.getWidgetById('textbox1');
const chartWidget = app.getWidgetById('chart1');
const featureServiceDataSource = chartWidget.dataSource;
textBox.on('change', (event) => {
const userInput = event.target.value;
const sqlQuery = `YourFieldName = '${userInput}'`;
featureServiceDataSource.setQuery({
where: sqlQuery,
outFields: ['*'],
});
chartWidget.refresh();
console.log(`Applied SQL query: ${sqlQuery}`);
});
To filter data in your Experience Builder chart:
const textBox = app.getWidgetById('textbox1');
const chartWidget = app.getWidgetById('chart1');
const featureServiceDataSource = chartWidget.dataSource;
textBox.on('change', (event) => {
const userInput = event.target.value;
const sqlQuery = `YourFieldName = '${userInput}'`;
featureServiceDataSource.setQuery({
where: sqlQuery,
outFields: ['*'],
});
chartWidget.refresh();
console.log(`Applied SQL query: ${sqlQuery}`);
});
@SumitMishra_016 can you please explain more about this? Are you suggesting to add text or drop down widgets in addition to the chart widget, or to configure the query within the chart widget? thanks!