1

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.com/highcharts.js\"></script>";
 echo "<script src=\"http://code.highcharts.com/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.com/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

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...)

3
  • I don't understand your question. Highcharts accepts data in the following formats: api.highcharts.com/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? Commented Jun 27, 2013 at 15:38
  • Welcome to stack overflow... Please do not post your updates as answer instead Edit your existing question Commented Jun 28, 2013 at 12:35
  • ok, sorry I will edit Commented Jun 28, 2013 at 12:39

2 Answers 2

4

Without 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Don't know why the OP didn't give you a tick, but this answered my questions simply and clearly. Thanks Sri.
0

Please take look at article about combine php array and Highcharts.

http://docs.highcharts.com/#preprocessing-data-from-a-database

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.