2016-02-26 29 views
0

我可以使用JSON文件中的數據元素作爲x,y值嗎?這是我的JSON文件,我想使用reading_bs作爲x值,並使用reading_date作爲y值。Forio Contour動態json數組

[ 
    { 
     "id": 76, 
     "user_id": 6, 
     "reading_date": "2016-02-23", 
     "reading_bs": 2, 
     "fasting": true, 
     "reading_notes": "test" 
    }, 
    { 
     "id": 77, 
     "user_id": 6, 
     "reading_date": "2016-02-24", 
     "reading_bs": 2, 
     "fasting": true, 
     "reading_notes": "test2" 
    }, 
    { 
     "id": 78, 
     "user_id": 6, 
     "reading_date": "2016-02-25", 
     "reading_bs": 2, 
     "fasting": true, 
     "reading_notes": "test3" 
    } 
] 

其他值在頁面的其他地方使用。

回答

0

您將需要map數組包括x ANDS Y,以後就可以包含在數據集中的任何其他屬性,但有沒有辦法來指定哪些領域採取X和Y:

data = data.map(function (item) { 
    item.x = item.reading_bs; 
    item.y = item.reading_date; 
    return item; 
}); 
+0

那麼,這不起作用?我不清楚你對x和y規格的評論。映射沒有那樣做? –

+0

我在單線圖上使用它。 JSON文件是否需要缺乏引號才能起作用,還是隻是JSFiddle的一件事? –

+0

另外,y軸可以是日期嗎?如果是這樣,那將如何工作? –