简体   繁体   中英

Google chart from php array with json encode

I'm trying to visualize a multiline chart. I don't get any error neither on js nor apache level. The page is just blank white. The json encoded array seems to be good. What is the issue?

This is my $rows :

echo json_encode($rows);
[
  ["2018-06-13",0,0,0,0,0,0],
  ["2018-06-14",1.37,1.37,1.37,0,1.37,0],
  ["2018-06-15",3.2,3.2,4.91,1.83,6.74,0],
  ["2018-06-16",4.45,9.25,6.16,5.24,14.95,0]
]

And this is the script:

function drawChart() {

  var data = new google.visualization.DataTable();
  data.addColumn('number', 'date');
  data.addColumn('number', 'user1');
  data.addColumn('number', 'user2');
  data.addColumn('number', 'user3');
  data.addColumn('number', 'user4');
  data.addColumn('number', 'user5');
  data.addColumn('number', 'user6');

  data.addRows(
    <?php echo json_encode($rows);?>
  );

  var options = {
    chart: {
      title: 'Points over time',

    },
    width: 900,
    height: 500,
    axes: {
      x: {
        0: {side: 'top'}
      }
    }
  };

  var chart = new google.charts.Line(document.getElementById('line_top_x'));
  chart.draw(data, google.charts.Line.convertOptions(options));
}

data.addColumn('number', 'date'); This line was the issue. Setting it to be string instead of number solved my issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM