【发布时间】:2014-11-27 13:22:00
【问题描述】:
我正在寻找在咖啡脚本中传递给我的多个数组中的最后一个值。我有一些代码可以产生类似的结果,但我无法将它们放在一起。 我在这里定义了一个值数组。
series = @_parseData {points: @get('points'), series: @get('series')}
这将为我提供一系列数组中的最大值。
maxvalue = Math.max(answer, (point?.y or 0)) for point in s.data for s in series
这将使我得到一个数组中的最后一个值。
data = series[0].data
answer = data[data.length - 1].y
这将得到多个数组中最后一个值的总和。
answer += s.data[s.data.length - 1].y or 0 for s in series
任何帮助将不胜感激。我的语法有问题。
不同系列中的值是为 Y 轴传递的数字,以使一条线位于人力车上。它们应该是诸如 200-15000 之类的数字。每次图表获得更多要绘制的数据时,X 轴基本上只是增加 30。
系列是从这个 ruby 函数传递的。 totinarr 和 totoutarr 只是用作增量计数器的数组。 totin 和 totout 是作为数据值传递的浮点数。
def graphfunction( totin, totinarr, totout, totoutarr, grphname )
if ( totinarr.last[:y] != totin) | ( totoutarr.last[:y] != totout )
totinarr.shift
totinarr.last[:x] += 30
totinarr << { x: totinarr.last[:x], y: totin }
totoutarr.last[:y] != totout
totoutarr.shift
totoutarr.last[:x] += 30
totoutarr << {x: totoutarr.last[:x], y: totout }
end
totdata = [
{
name: "graph1",
data: totinarr
},
{
name: "graph2",
data: totoutarr
}
]
send_event( grphname , series: totdata)
return true
end
【问题讨论】:
-
您能提供示例数据吗?变量似乎并不总是指同一件事。
-
如果我们知道
series的样子和结果应该是什么,可能会有所帮助。 -
我添加了一些信息。样本数据将是一个包含 X 和 Y 值的系列(X 只是一个增量,Y 是从 0 到 15000 的编号值)。这有帮助吗?
标签: arrays coffeescript