I'm making charts for my app and I've experienced problem with dynamic variables. The variable for one single line on the chart looks like:
var trace1 = {
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: 'scatter'
};
It has to look like this:
[
var trace1 = {
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: 'scatter'
},
var trace1 = {
x: [1, 2, 3, 4],
y: [10, 15, 13, 17],
type: 'scatter'
}
]
But it has to be dynamic: I will ask server for the amount of lines. And the problem now is to make as many trace[i]
variables as the server says. For example, if the response is 3, it has to make three variables:
trace1 = {}, trace2 = {}, trace3 = {}
And it has to be inside array:
[trace1 = {}, trace2 = {}, trace3 = {}]
My question is: it is even possible to do something like this? A loop which will make for example there 3 variables in an array?
This is my goal:
[trace1 = {}, trace2 = {}, trace3 = {}]