[英]Create dynamic object for angular chart
我想创建一个动态的对象,像这样与Angular Chart一起使用。
[{
id:0,
name: 'WI',
type: 'NI',
labels: ["January", "February", "March", "April", "May", "June", "July"],
data: [[28, 48, 40, 19, 86, 27, 90]]
}];
我创建了一个名为LineChart的类:
public class LineChart
{
public int Id { get; set; }
public string Name { get; set; }
public string[] Labels { get; set; }
public int[] Data { get; set; }
}
public async Task<HttpResponseMessage> GetInformation()
{
try
{
string[] labels = new string[7] {"January", "February", "March", "April", "May", "June", "July"};
int[] numbers = new int[] { 28, 48, 40, 19, 86, 27, 90 };
List<LineChart> line = new List<LineChart>();
LineChart linechart = new LineChart();
linechart.Id = 0;
linechart.Name = "WI";
linechart.Data = numbers;
linechart.Labels = labels;
line.Add(linechart);
return Request.CreateResponse(HttpStatusCode.OK, line);
}
catch (SqlException)
{
return Request.CreateErrorResponse(
HttpStatusCode.ServiceUnavailable,
"The service is temporarily unavailable. Please try again at a later time.");
}
catch (Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, e);
}
}
问题出在数据上,我的格式如下:[28,48,40,19,86,27,90]为什么在[[28,48,40,19,86]之间应该有双括号,27,90]]。
在双括号之间获取数据的最佳方法是什么? 像[[和我的数据]]
从收到的评论中,我将如何做:
string[] labels = new string[7] {"January", "February", "March", "April", "May", "June", "July"};
int[] numbers = new int[] { 28, 48, 40, 19, 86, 27, 90 };
var arrayHolder = new List<int[]>();
arrayHolder.Add(numbers);
List<LineChart> line = new List<LineChart>();
LineChart linechart = new LineChart();
linechart.Id = 0;
linechart.Name = "WI";
linechart.Data = arrayHolder.ToArray();
linechart.Labels = labels;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.