创建角度图的动态对象

我想创建一个像这样的动态对象,以便在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]。

将数据放在双括号内的最佳方法是什么?就像[这是我的数据]

转载请注明出处:http://www.sywsjj.net/article/20230330/1541788.html