首页 > 解决方案 > Highchart 仅在本地主机上正确显示

问题描述

当我Uncaught SyntaxError: Unexpected token '<'尝试将其上传到 webhost 时出现错误,而当我使用 localhost 时它正确显示而没有任何错误。我使用的 php 版本也与 webhost 相同。

这是我在控制台错误中发现的 在此处输入图像描述

这是highchart代码

   $(function(){
  var chart = new Highcharts.Chart({
      chart: {
          renderTo: 'graph',
          scrollablePlotArea: {minWidth: 700},
      },
    xAxis: {
      categories: [<?php echo join($arrayTanggal, ',') ?>],
      tickWidth: 0,
      gridLineWidth: 1,
      labels: {
        align: 'left',
        x: -40,
        y: -3
      }
    },
    yAxis: [{ // left y axis
    title: {
      text: null
    },  
    labels: {
      align: 'left',
      x: 3,
      y: 16,
      format: '{value:.,0f}'
    },
    showFirstLabel: false
  }, { // right y axis
    linkedTo: 0,
    gridLineWidth: 0,
    opposite: true,
    title: {
      text: null
    },
    labels: {
      align: 'right',
      x: -3,
      y: 16,
      format: '{value:.,0f}'
    },
    showFirstLabel: false
  }],
    legend: {
      align: 'left',
      verticalAlign: 'top',
      borderWidth: 0
    },
    tooltip: {
      shared: true,
      crosshairs: true
    },
    series: [{
      name: 'Overall',
      color: '#dc3545',
      data: [<?php echo join($arrayAverage, ',') ?>],
      lineWidth: 3,
      marker: {
        radius: 8
      }
    },]
  });
});

感谢您提供的任何帮助

标签: javascripthighcharts

解决方案


在 PHP 中,joinimplode. 所以正确的语法是implode ( string $glue , array $pieces ) : string.

答案是:

<?php echo implode(',', $arrayTanggal) ?>

推荐阅读