2013-03-12 30 views
0

这可能是一件非常简单的事情,但一直未能弄清楚。我有一个带有图例的多线图。我已经按照下面的格式指定了parameter_id作为关键字。访问键值?

Array[3] 
0: Object 
key: "1" 
values: Array[11] 
0: Object 
client_id: "1" 
dateTimeReceived: "2013-03-12 05:54:10" 
dateTimeTaken: Tue Mar 12 2013 05:53:41 GMT+0000 (GMT Standard Time) 
id: "1" 
inspectionPoint_id: "1" 
parameterType: "Temperature" 
parameter_id: "1" 
reading: 2.1 
testSourceLocationDescription: "test source" 
testSourceLocationLatitude: "53.000000000000000" 
testSourceLocationLongitude: "-7.000000000000000" 
testSourceLowerLimit: "4" 
testSourceUpperLimit: "25" 
testSource_id: "1" 
unitMeasurement: "°C" 
__proto__: Object 

我的问题是,明明传说文本显示的ID - 但我想它显示的参数类型。我是否需要将parameterType指定为第二个键(如果可能,请避免此操作),还是有任何方法可以访问此值?

PS - 我最初使用parameterType作为键,但元素在更新时未被正确绑定。

+0

你是如何生成的图形? – 2013-03-12 13:40:46

+0

这里 - https://gist.github.com/Majella/ab32fe0151fd487da3f6 – Newbie 2013-03-12 14:43:21

+0

你有没有尝试改变legend.append('文本')下的文本“.text(function(d){return d.key;}) “to”.text(function(d){return d.parmae​​terType;})“ – 2013-03-12 14:50:13

回答

0

只需在您的要点从

.text(function(d){ return d.key; }) 

改线72

.text(function(d){ return d.values[0].parameterType; }) 
+0

谢谢,但我已经尝试过,并且在更改为d.parameterType时不显示任何文本 – Newbie 2013-03-12 15:54:17

+0

好了,不再理解你的问题了。代码对我来说工作正常 - 请参阅[这里](http://jsfiddle.net/rgsbY/)。 – 2013-03-12 16:13:57

+0

如上所述,当我之前将参数key改变为参数类型时,数据在更新时未被正确绑定 - 每次更新时线都跳过,这就是为什么我将数据绑定到一个id的原因。在你的例子中,它不仅仅是你已经改变为parameterType的文本函数,而是关键字 - 当图形是静态的时候工作,而不是在更新时工作。 – Newbie 2013-03-12 16:24:08