0

I have this code in javascript for chart column:

$(function () {
  $('#grafic_column').highcharts({
    chart: {
            type: 'column'
        },
    series: [{
      name: 'Population',
      data: [
        ['Shanghai', 23.7],
        ['Lagos', 16.1],
        ['Istanbul', 14.2]
      ]
    }]
  });
});

And this cod in php:

<?php
$ar = array(
  ['Shanghai', 23.7],
  ['Lagos', 16.1],
  ['Istanbul', 14.2]
);
echo json_encode($ar);
?>

How do import the values results from php in series.data:? Thank you!

4
  • Is the JavaScript code being served from your php server? Commented Aug 31, 2016 at 22:55
  • 2
    data: [ <?php echo json_encode($ar); ?> ] ? Commented Aug 31, 2016 at 23:08
  • @Sherif, I tried so: data: [ <?php include'myfile.php'; echo json_encode($ar); ?> ], and not work. Commented Aug 31, 2016 at 23:49
  • 1
    does myfiles.php contain your data? if so include it in the top of your script and assing the data content to $ar and just do data: [ <?php echo json_encode($ar); ?> ] Commented Aug 31, 2016 at 23:51

1 Answer 1

2

Assuming your PHP file is accessible with a server, you can just perform $.get to make an AJAX request to the file serving the data:

$(function () {
    $.get('/yourphpfile.php').then(function(data) {
        $('#grafic_column').highcharts({
            chart: {
                type: 'column'
            },
            series: [{
                name: 'Population',
                data: data
            }]
        });
    })
});
Sign up to request clarification or add additional context in comments.

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.