如何从API向图添加数据

时间:2019-01-31 08:55:07

标签: livecode

我想制作一个股票应用,其中过去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轴外,图形上没有任何显示。我在这里做什么错了?

1 个答案:

答案 0 :(得分:0)

我尝试了以下似乎可行的变体。一个问题是您的数据在每一行的末尾包含的交易量比交易值高,因此,我从图表所用的每一行中删除了该值。

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