如何从 API 向图表添加数据

How to add data to a graph from an API

我想制作一个股票应用程序,过去 7 天的股票价值以图表形式显示。这是从 API:

中提取数据的代码
on mouseUp
   put url("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=YPMBUVQ8AJXX1HQP&datatype=csv") into myData
   put myData into field "Data"

   set the itemdel to ","
   put 1 into x
   repeat until x > 8
      add 1 to x
      put items 1 to 5 of line 5 of myData & return after gData
   end repeat
   set the graphData of widget "graph" to gData
end mouseUp

第一项为x轴,其余均为y轴。但是当我 运行 这段代码时,它只将一行放入图形的 graphData 中,除了 2 轴外,图形上没有显示任何内容。我在这里做错了什么?

我尝试了以下似乎有效的变体。一个问题是您的数据在每条线的末尾包含一个与交易值相比超高的交易量,因此我从用于图表的每条线中删除该值。

on mouseUp
   put url("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=YPMBUVQ8AJXX1HQP&datatype=csv") into temp
   delete line 1 of temp -- REMOVE THE COLUMN LABLES
   delete line 8 to -1 of temp -- LIMIT DATA TO 7 DAYS
   repeat for each line theLine in temp
      delete last item of theLine -- IGNORE VOLUME (NUMBER IS TOO LARGE COMPARED TO TRADING DATA)
      put theLine & return after myData
   end repeat
   set the graphData of widget "graph" to myData
end mouseUp