Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Create a JSON from the found set to use in a java-chart

Featured Replies

I'm learning JSON to collect data into a java graph. The reason is that I want to show the answers to a survey question in a line chart. The table structure looks like this:

90893302_ScreenShot2019-10-25at12_37_22.thumb.png.f1282d4e5706eb0c14f860bc5f98fb14.png

(I do not know why the graph shows the relationships as many to many, they are not, but it is actually one to many. If anyone knows why it is like this then please tell..)

I have a list view based on the responses table. I want the graph to show the requested result in the list view. The results are always from one question but the question is asked three times a day (in three different surveys) so there are three lines per date. The fields in the list view that I would like to collect in a JSON are
SurveyMoment::date (date)
Svara » Survey::name (text)
Responses::answer (number)
I would like a graph showing three lines where each line shows the answers from the different surveys. Currently, my script that creates JSON looks like this:

694370679_ScreenShot2019-10-25at12_51_58.png.ab5a0a025d4cfd0fd6b15f1951857086.png

The calculation in the Set Variable on row 7 is this:
JSONSetElement ( $theArray ; "[" & $index & "]" ; 

JSONSetElement ( "" ; 
["date" ; Responses::date; JSONString ] ;
["answer" ; Responses::answer; JSONNumber] ;
["survey" ; Svara » Survey::name; JSONString]
)

; JSONObject )

Which results in a JSON that looks like this:
[
    {
        "answer" : 3,
        "date" : "2019-10-07",
        "survey" : "Survey 1 morning"
    },
    {
        "answer" : 3,
        "date" : "2019-10-07",
        "survey" : "Survey 2 lunch”
    },
    {
        "answer" : 2,
        "date" : "2019-10-07",
        "survey" : "Survey 3 evening"
    },
    {
        "answer" : 1,
        "date" : "2019-10-08",
        "survey" : " Survey 1 morning "
    },
    {
        "answer" : 2,
        "date" : "2019-10-08",
        "survey" : "Survey 2 lunch"
    },
    {
        "answer" : 2,
        "date" : "2019-10-08",
        "survey" : "Survey 3 evening"
    }, 
etc…..
]

This works if I constrain the result so that it only shows answers from one survey. But if I want three lines in the graph then JSON would have to look like the following.
[
    {
        "date" : "2019-10-07",
        "survey 1 morning" : 3,
        "survey 2 lunch" : 3,
        "survey 3 evening" : 2
    },
    {
        "date" : "2019-10-08,
        "survey 1 morning" : 1,
        "survey 2 lunch" : 2,
        "survey 3 evening" : 2
    }, 
etc…..
]

Anyone know how to create it based on the found set in the list layout based on the Responses-table? The idea is that I can filter the found set by choosing the question I want to see the answers from and choosing the time period. So, every time the found set is updated, the chart should be updated automatically and only show the answers from the found set.
 

Thanks!

Edited by andersmnystrom

This is a great exercise in constructing JSON. See if the attached demo works for you.

 Grouped2JSON.fmp12

 

4 hours ago, andersmnystrom said:

why the graph shows the relationships as many to many,

Because Filemaker doesn't know it's supposed to be one-to-many. You need to either validate the parent's ID field as unique, or make it auto-enter a serial number/UUID.

 

Edited by comment

  • Author

Thanks! i will look at the demo tonight. 

That's what is so strange. The parent Id fields are set as unique and Im using Get ( UUID ) as auto-enter but still it looks like many to many in the relational graph.

19 minutes ago, andersmnystrom said:

The parent Id fields are set as unique and Im using Get ( UUID ) as auto-enter but still it looks like many to many in the relational graph.

Can you post a file showing that?

  • Author
2 hours ago, comment said:

Can you post a file showing that?

Sure but I cant get it to upload. Going to try again a little later or try to send it to you via pm.  But in practice, I think it works as one to many relationships but that the relationship graph shows it wrong for some reason. It became this way when I started to use FileMaker 17 and then the same in 18. If I open the same file in FileMaker 16, everything looks right....

fm16.png.46119444e2b8857239f69c50a8f1e076.png

Big thanks for your demo file! Looked at it a bit now and it seems to work just as I wanted it. Going test it in my file now.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.