I want to create dynamic an Object like this for using it with Angular Chart.
[{
id:0,
name: 'WI',
type: 'NI',
labels: ["January", "February", "March", "April", "May", "June", "July"],
data: [[28, 48, 40, 19, 86, 27, 90]]
}];
I created a class named 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);
}
}
The problem is with the Data, I have it in a form like this : [28, 48, 40, 19, 86, 27, 90] why there should be double brackets between like [[28, 48, 40, 19, 86, 27, 90]].
What is the best way to get your data between double brackets? Like [[ and here goes my data ]]
[[that means it would be an array in another array? What you declared for Data is an array of intpublic int[] Data { get; set; }