I have problem with adding points to chart (CanvasJS).
here how I store points manually but I need to add it dynamically
var dps = [{ x: 1, y: 10 }, { x: 2, y: 10 }, { x: 3, y: 10 }, { x: 4, y: 10 }, { x: 5, y: 10 }, { x: .., y: ..}, ... .... ...]; //dataPoints.
How Can I add to dps points which are in my ViewData["XPoints"] and ViewData["YPoints"] ?
I was thinking about foreach but I don't know how to use it.
@foreach (var pk in ViewData["XPoints"] as List<int>)
{
@pk
}
EDIT:
Ok maybe it's not so clear.
I have got two ViewData with X and Y points. ViewData.["XPoints"] and ViewData.["YPoints"] which are storing numbers.
Now I have to make an array like DPS using this numbers.
var DPS = [{x: .., y: ...},{x: .., y: ...},{x: .., y: ...},{x: .., y: ...},.....].
How Can I achieve it?
EDIT2
I solved it, here is How I did it
var myArrayX = [];
var myArrayY = [];
var arry = [];
@foreach (var st in ViewData["XPoints"] as List<int>)
{
@:myArrayX.push(@st);
}
@foreach (var st in ViewData["YPoints"] as List<int>)
{
@:myArrayY.push(@st);
}
for (var i = 0; i < myArrayX.length; i++) {
arry.push({ x: myArrayX[i], y: myArrayY[i], });
}