Charts not rendering when for data source microflow

0
I am trying to render a custom chart where the data source is set to a microflow, using Charts module. I am getting the following error. If I try to achieve the same functionality using Database, as datasource, then it works perfectly. Issue is when I use the microflow and then use the Export mapping to convert the non-persistent objects to JSON and pass JSON as source. I need this microflow approach because I want to put a filter on the page where upon selecting a value from dropdown the chart will be updated with relevant data fetched from DB.   Error parsing chart data:JSON.parse is not a function or its return value is not iterable TypeError: JSON.parse is not a function or its return value is not iterable    at http://localhost:8080/widgets/com/mendix/widget/web/customchart/CustomChart.js?638851109732697250:1:57477    at get data (http://localhost:8080/widgets/com/mendix/widget/web/customchart/CustomChart.js?638851109732697250:1:57593)    at ee (http://localhost:8080/widgets/com/mendix/widget/web/customchart/CustomChart.js?638851109732697250:1:19753)    at e.computeValue_ (http://localhost:8080/widgets/com/mendix/widget/web/customchart/CustomChart.js?638851109732697250:1:18016)    at e.trackAndCompute (http://localhost:8080/widgets/com/mendix/widget/web/customchart/CustomChart.js?638851109732697250:1:17860)    at e.get (http://localhost:8080/widgets/com/mendix/widget/web/customchart/CustomChart.js?638851109732697250:1:17096)    at e.getObservablePropValue_ (http://localhost:8080/widgets/com/mendix/widget/web/customchart/CustomChart.js?638851109732697250:1:43665)    at pr.get (http://localhost:8080/widgets/com/mendix/widget/web/customchart/CustomChart.js?638851109732697250:1:48461)    at get chartProps (http://localhost:8080/widgets/com/mendix/widget/web/customchart/CustomChart.js?638851109732697250:1:57211)    at ee (http://localhost:8080/widgets/com/mendix/widget/web/customchart/CustomChart.js?638851109732697250:1:19753)        
asked
1 answers
0

Hi Kiran,  If you get the error:

Error parsing chart data: JSON.parse is not a function or its return value is not iterable

 

when using a microflow as the data source for a custom chart in the Charts module, here’s what you need to check and do:

  1. Your microflow must return a single String containing valid JSON not an object or list. Use an Export Mapping to convert your non-persistent objects to a JSON string.

  2. Set the microflow return type to String and ensure it outputs the JSON string generated by the export mapping.

  3. In the chart widget, select the microflow as the data source. The widget will internally call JSON.parse on the returned string to get the data.

  4. When the user changes the filter (e.g., dropdown), trigger the microflow again to fetch filtered data and update the JSON string, which will refresh the chart.

This approach fixes the parsing error because the chart widget expects a JSON string to parse, not an already parsed object.

 

Hope this helps :)

 

Still issues was not solved share me picture for more clarity.

answered