Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How to connect JSON to chart

Issue

I'm having trouble displaying data from an internal API in a chart. The API returns JSON and I want to display one measure on the y axis over time on the x axis. I'm not sure what to put in the chart's series data field. I've tried using the JSON data source named WxAPI but it's not working. Can someone help me figure out how to display the data properly?

Resolution

The solution to displaying data from the internal API is to parse the JSON response and extract the required data. In this case, we want to display T_SFC over time. We can create a list of dictionaries where each dictionary represents a data point on the chart. The x value will be the time and the y value will be the T_SFC.

Here's an example code snippet:

import json

response = '{"FireWeatherData":[{"time":1664852400000,"T_SFC":20.8000011444}, ...'

data = json.loads(response)
chart_data = []

for entry in data["FireWeatherData"]:
chart_data.append({"x": entry["time"], "y": entry["T_SFC"]})

# use chart_data to display the chart

We first load the JSON response into a Python dictionary using the json.loads method. We then iterate over each entry in the "FireWeatherData" list and create a dictionary with the "time" and "T_SFC" values. We append this dictionary to the chart_data list.

We can then use the chart_data list to display the chart using whichever charting library we are using.