[SOLVED] Chart from API json

Hi im running into an issue trying to get a chart to render with points pulled from a JSON API. Perhaps someone can show me where Im going wrong.

my API is returning the following example JSON

{
“Data”:[18,18,18,0,29,29,29,30,29,35,35,23,24,7],
“Time”:[0,5,10,15,20,25,30,35,40,45,50,55,60,65]
}

I created a new type called chart_data with two fields, a list of data and a list of time

Next I made a “when page is loaded” workflow to Create a new Thing of chart_data and set the fields with set lists.

Now when I come to create the chart, I set the data source to be search for chart_datas, the label expression I can set to current point’s date just fine, it goes blue, but when I come to set the value expression to current point’s value, it stays red and says “a value expression should be a number but right now its a list of numbers”

the label expression entry seems happy being provided with a list, how come the value expression cant take a list as argument for current point’s thing?

How do I get the chart points from the API into the chart.js plugin? is my json format wrong?

There are a lot of touch points here that can go wrong. Would you mind sharing a link to the editor so we can help diagnose?

Heres a link to the issue

Anyone have any input here? I suspect from info gleaned from other posts that the issue is with lists and chart.js. So I would be glad to use a table of numbers instead, but how do I populate a table of type numbers from a JSON returning a list from an API call?

Maybe I should consider formatting JSON as [{x1,y1},{x2,y2},{xn,yn}] instead of [{x1,x2,xn},{y1,y2,yn}] ? ill give it a try and report back.

solved! I found I didnt need to pull the json into a table at all, I could simply select the API connector as the data source for the chart directly. I did still need to format the JSON as a list of x,y points to make it work.

2 Likes

I just noticed I had a draft response to this post I never posted. Sorry!

I’m glad you figured it out. I was going to tell you I haven’t used the chart plugin yet, so I was no help. I’m glad you were able to sort it out, that’ll be helpful for the other members of the community!

How did you reformat / merge the JSON data?