javascript - How can I add a "for" in a Highcharts series? -
i have .php file executes query, query adds textfields depending on results, example:
$query = mysqli_query($mysqli, "select year,period users"); $num_users = mysqli_num_rows($query); for($i=1; $i<=$num_users; $i++) { $row = mysqli_fetch_array($query); echo "<input type='text' id='year$i' name='year$i' value='".$row['year']."'>"; echo "<input type='text' id='period$i' name='period$i' value='".$row['period ']."'>"; } echo "<input type='text' id='count' name='count' value='$num_users'>"
so output x-number of inputs, may 1 40 inputs containing year , period, catch values of fields following:
count = parseint(document.getelementbyid('count').value); for(i=1;i<=count;i++) { var custom = "year" + i; window[custom] = parsefloat(document.getelementbyid('year' + i).value); var custom = "period" + i; window[custom] = parsefloat(document.getelementbyid('period' + i).value); }
until point works well, i've tested above code , inputs values being saved in right variable.
how can have series in display theses ages having in mind number of data change?
i thinking this:
series: [ for(i=1;i<=count;i++) { { name: year + i, data: [period + i] } } ]
please me!! thanks!!
series
must array. if want use function populates array can create self executing function (updated demo, output textarea):
series: (function(year, period, count) { var data = []; for(i=1;i<=count;i++) { data.push( { name: year + i, data: [period + i] } ); } return data; })(year, period, count)
this assumes have external values year
, period
, count
Comments
Post a Comment