How can I plot the stringified json data in charts?

image
I'm getting this error when I run it in mit app inventor.

Put the output of this

image

should look something like:

https://script.google.com/macros/s/AKfycby-111119uHuBe0_DVUKfv-EQLM1i1BbioCsUgPyK8Ih0aCh6ZD-uUweNi37TLiqt6zRg/exec?history=30

into your computer browser, what do you get back ?

[["Date","Systolic","Diastolic"],["2023-08-21","118.00","78.00"],["2023-08-22","108.00","78.00"],["2023-08-23","126.00","80.00"],["2023-08-24","120.00","78.00"],["2023-08-25","118.00","80.00"],["2023-08-28","108.00","70.00"],["2023-08-29","120.00","80.00"],["2023-08-30","132.00","82.00"],["2023-08-31","122.00","80.00"],["2023-09-01","116.00","68.00"],["2023-09-02","118.00","84.00"],["2023-09-04","122.00","78.00"],["2023-09-05","114.00","80.00"],["2023-09-07","118.00","77.00"],["2023-09-08","122.00","72.00"],["2023-09-09","103.00","83.00"],["2023-09-11","125.00","75.00"],["2023-09-13","120.00","70.00"],["2023-09-15","118.00","84.00"],["2023-09-21","129","98"]]

I'm getting this.

And I tried again and am getting the plot. The plot includes all the 20 entries tho. How can I get the plot of 7 entries ?

image

Change 30 to 7


yah, I tried it and only 4 values are being displayed!!

@TIMAI2 Thank you for your help so far.

I have tried to modify the code in my apps script and have obtained the response content (in Label 1) as like:

"[["Thu Sep 07 2023",118,77],["Fri Sep 08 2023",122,72],["Sat Sep 09 2023",103,83],["Mon Sep 11 2023",125,75],["Wed Sep 13 2023",120,70],["Fri Sep 15 2023",118,84],["Thu Sep 21 2023",129,98]]"

and my decoded jsonArray (in Label 2) as like:

[["Thu Sep 07 2023",118,77],["Fri Sep 08 2023",122,72],["Sat Sep 09 2023",103,83],["Mon Sep 11 2023",125,75],["Wed Sep 13 2023",120,70],["Fri Sep 15 2023",118,84],["Thu Sep 21 2023",129,98]]

image

Now, I just need help to segregate the data and plot in chartmaker. It says I can’t use a list. So pls can you look into it?

You do not have a header row.

Either, include this in your script (it is already in my script):
arr.unshift([data[0][1],data[0][2],data[0][3]]);

or insert it to the list before displaying the chart:

image

I have also made a small edit to the script to convert number strings to integers (see above), which means the little procedure I used is no longer necessary.

1 Like

It says that my global jsonArray is a 'string' and not a 'list' :disappointed_relieved:
image

Also I have used the '.unshift' function. I love it, Thanks!

Check this is true:

image

Change this

image

to this

image

This is working for me (with my script above)

I've intialized 'jsonArray' as a string. My bad!!

it's false. Not a list!!

your script is working fine with me too (i tried it as a separate project). But, I am working with other screens too. So, I thought i might give my script a shot.

Check the content of your responseContent, if that looks like a stringified json array, then see what happens when you use the decode block on it. If you are not getting back a stringified array, then you need to look at your script.

1 Like

image


Response Content & decoded jsonArray

A great thanks to you @TIMAI2 :cowboy_hat_face: :partying_face:

I just tried to decoded the json string again (like twice), then it was a LIST! and I plotted the data. :star_struck:

1 Like

I tried to plot again today. It's showing this error:

Data column for axis #0 cannot be type string

This is my block.

Why are you using jsontextdecode block twice ?

Haven't you already added the header row in the script ?

As I have already said before, the first decoded text looks like a json text, but it seems it's not.
The response content is in a string format, so is the firstly decode jsonString. Only the jsonArray (jsonString after being decoded again) is in the list format.

I was able to plot it yesterday, when I was only using the 7 data... Now that I've added 30 data, It says the above mentioned error.

Yes, I have.

Then do not add it again. This will put strings in the plot data when expecting numbers

If I'm not adding it again, it says the decoded json is a string and not a list.

Do I have to add the little procedure that you've added before?

I was talking about the header row you are adding in the blocks!

You should not have to jsontextdecode twice to get a list, if you are returning a stringified JSON array correctly, as shown by my example.

1 Like

yah, i realized that my json string was stringified twice in my script (I didn't notice), hence I have to decode it twice. Now it's fine with one block.

And I used the little procedure you have suggested before. And it PLOTS!!

Thank you so much @TIMAI2. Thank you for your patience & timely help. May God bless :sparkles:

1 Like