2015-04-22 20 views
0

我試圖填充在JavaScript的一些圖形數據與一些C#代碼C#序列化到jQuery的

這裏是C#:

var publicationTable = new[] { 
    new[] { month.Select(x => Convert.ToDouble(x.RoomCount)).ToArray() }, 
    new[] { month.Select(x => x.HoursCount).ToArray() } 
}; 

return (new JavaScriptSerializer()).Serialize(publicationTable); 

的Javascript:

height: 375, 
xGrid: false, 
legend: true, 
title: 'Meetings and Hours Used (Coming Soon!)', 
points: <%= getJson() %>, 

下面的C#代碼作品:

public string getJson() { 

var publicationTable = new[] { 
    new[] { 1, 2, 3, 4, 5 }, 
    new[] { 6, 7, 8, 9, 10 } 
}; 
return (new JavaScriptSerializer()).Serialize(publicationTable); 
} 

月是元素RoomCount(int)和HoursCount(浮動)

Output http://i58.tinypic.com/9h8j6e.png

編輯說列表:它看起來像正在把整個序列化在圖形的第一個元素(見圖片)

+0

請發佈實際呈現的響應。 – Dai

+0

分:[[[1,2,3,4,5,6,7,8,9,10,11,1,2,3,4,5,6,1,2,3,1,2, 1,2,3,4,5,6,7,8,9,10,11,1,2,3,4,5,6,7,8,9,1,2,3,4,5, 6]],[[0,0,0,0,1,2,3,3,4,4,5,5,5,5,5,5,5,5,5,5,6,6, 7,7,8,9,10,10,10,11,11,12,13,14,14,15,16,17,17,18,19,20,20,21,22,23,23, 24]]], – Corbin

+0

它似乎有一個額外的[]圍繞它 - 我怎麼去除它們? – Corbin

回答

0

你試過:

var publicationTable = new[] { 
    month.Select(x => Convert.ToDouble(x.RoomCount)).ToArray(), 
    month.Select(x => x.HoursCount).ToArray() 
}; 

.toArray()已經返回一個數組,所以它不需要new[](要創建陣列的方式,與第一個元素是另一個數組)