I'm trying to display a chart with highcharts. I have a 2-dimension-Array with values for Inductance and Current. How can I use that data to display a chart? I was looking for it, but I didn't find the correct answer... In the highcharts demos there are only cases wich you write directly the values, but never use an Array. I'm using html+php+javascript in my web page. If someone could help me, I would appreciate so much.
Thanks in advance and best regards.
P.S: If someone knows another way to display charts easier, I also would appreciate.
EDIT:
Thanks for answer. I think that I don't understand so well this library... I will post my code
//I initialize the array with the name Array_L_I_XXXX with the results from my SQL query
while($row4 = mysqli_fetch_array($result3))
{
$Array_L_I_XXX[j][0] = $row4['L_value'];
$Array_L_I_XXX[j][1] = $row4['I_value'];
$j++;
}
echo "<div style=\"margin: 0 1em\">";
echo "<script src=\".js\"></script>";
echo "<script src=\".js\"></script>";
echo "<div id=\"container\" style=\"min-width: 400px; height: 400px; margin: 0 auto\"></div>";
Also, in the <head>
part, I have the following code
<script type="text/javascript">
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
series: [{
data: [<?php echo join($Array_L_I_XXX, ',') ?>],
pointStart: 0,
pointInterval
}]
});
</script>
That doens't work (for sure is so wrong...) but really I can't find the correct way to do this... Thanks!
I have my 2D-array in php
Array_L_I[X][Y]
, and now, I insert the following code to call the highchart function:echo ""; echo ".js\">";
echo "<div id=\"container\" style=\"min-width: 400px; height: 400px; margin: 0 auto\"></div>";
- In the
<head>
section I have the code Highchart conde
- In the
My problem is that I don't know how to "send" this array to the highchart function to use my values (It is not like a js function that I can send some variables...)
I'm trying to display a chart with highcharts. I have a 2-dimension-Array with values for Inductance and Current. How can I use that data to display a chart? I was looking for it, but I didn't find the correct answer... In the highcharts demos there are only cases wich you write directly the values, but never use an Array. I'm using html+php+javascript in my web page. If someone could help me, I would appreciate so much.
Thanks in advance and best regards.
P.S: If someone knows another way to display charts easier, I also would appreciate.
EDIT:
Thanks for answer. I think that I don't understand so well this library... I will post my code
//I initialize the array with the name Array_L_I_XXXX with the results from my SQL query
while($row4 = mysqli_fetch_array($result3))
{
$Array_L_I_XXX[j][0] = $row4['L_value'];
$Array_L_I_XXX[j][1] = $row4['I_value'];
$j++;
}
echo "<div style=\"margin: 0 1em\">";
echo "<script src=\"http://code.highcharts./highcharts.js\"></script>";
echo "<script src=\"http://code.highcharts./modules/exporting.js\"></script>";
echo "<div id=\"container\" style=\"min-width: 400px; height: 400px; margin: 0 auto\"></div>";
Also, in the <head>
part, I have the following code
<script type="text/javascript">
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
series: [{
data: [<?php echo join($Array_L_I_XXX, ',') ?>],
pointStart: 0,
pointInterval
}]
});
</script>
That doens't work (for sure is so wrong...) but really I can't find the correct way to do this... Thanks!
I have my 2D-array in php
Array_L_I[X][Y]
, and now, I insert the following code to call the highchart function:echo ""; echo "http://code.highcharts./highcharts.js\">";
echo "<div id=\"container\" style=\"min-width: 400px; height: 400px; margin: 0 auto\"></div>";
- In the
<head>
section I have the code Highchart conde
- In the
My problem is that I don't know how to "send" this array to the highchart function to use my values (It is not like a js function that I can send some variables...)
Share Improve this question edited Jun 28, 2013 at 13:00 Bill the Lizard 406k212 gold badges574 silver badges892 bronze badges asked Jun 27, 2013 at 14:58 MastorMastor 1894 silver badges15 bronze badges 3- I don't understand your question. Highcharts accepts data in the following formats: api.highcharts./highcharts#series.data. These are of course javascript datatypes since Highcharts is a javascript product. So, are you asking how to convert your 2d PHP array to a 2d javascript array? – Mark Commented Jun 27, 2013 at 15:38
- Wele to stack overflow... Please do not post your updates as answer instead Edit your existing question – Hemantwagh07 Commented Jun 28, 2013 at 12:35
- ok, sorry I will edit – Mastor Commented Jun 28, 2013 at 12:39
2 Answers
Reset to default 4Without much details, I'll assume you are returning a PHP array and need to convert it into a JS array for use in HighCharts:
<script type="text/javascript">
js_array = new Array(<?php echo implode(',', $php_array); ?>);
</script>
HighCharts:
series: [{
data: js_array
}]
Follow this basic example and you can fine tune it for your project.
Please take look at article about bine php array and Highcharts.
http://docs.highcharts./#preprocessing-data-from-a-database
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745248023a4618505.html
评论列表(0条)