0

ハイチャートに JSON データを入力する際に​​問題が発生しています。Web ページでスクリプトを実行すると、グラフが必要とする特定の領域にデータが入力されますが、highcharts を使用しようとすると何も表示されません。

PHP を削除して静的な数値をプラグインすると、グラフが自動的に作成されます。

要約すると、php スクリプトを実行すると (ただし、データは生成されます)、Highcharts は機能しません。また、静的な数値を挿入して php スクリプトを削除すると、グラフが実行されます。

  $response = file_get_contents('https://graph.facebook.com/'.FACEBOOK_PAGE_ID.'/insights  /page_views?access_token='.FACEBOOK_ACCESS_TOKEN);
  $page = json_decode($response);



 if ($page && $page->data) {

$test = $page->data[0]->values[2]->end_time; $newDate = date("d-m-Y", strtotime($test));  
$gender = $page->data[0]->values[2]->value; 

$test2 = $page->data[0]->values[1]->end_time;  $newDate1 = date("d-m-Y", strtotime($test2)); 
$gender1 = $page->data[0]->values[1]->value; 

$test3 = $page->data[0]->values[0]->end_time;  $newDate2 = date("d-m-Y", strtotime($test3)); 
$gender2 = $page->data[0]->values[0]->value; 


}

 header('Content-Type: application/json');
 ?>
 {
 chart: {
  renderTo: 'container',
  height: 220,
  type: 'column'
  },
  title: {
  text: ''
  },
  xAxis: {
  categories: ['apples'],
  lineWidth: 0,
  tickWidth: 0,
   },
   yAxis: {
   min: 0,
   title: {
   text: ''
   },
  stackLabels: {
   enabled: true,
   style: {
   fontWeight: 'bold',

   }
   }
   },
   legend: {
   align: 'left',
   x: 0,
   verticalAlign: 'left',
   y: 15,
   floating: true,
   backgroundColor: 'white',
   borderColor: '#CCC',
   borderWidth: 1,
   shadow: false
    },
   tooltip: {
   formatter: function () {
   return '<b>' + this.x + '</b><br/>' + this.series.name + ': ' + this.y + '<br/>' +
   'Total: ' + this.point.stackTotal;
   }
   },
   plotOptions: {
   column: {
   stacking: 'normal',
    dataLabels: {
   enabled: true,
   color: 'white'
   }
   }
   },
        series: [{
            name: '<?php echo $newDate; ?> ',
            data: [<?php echo $gender; ?>]
        }, {
            name: '<?php echo $newDate1; ?>',
            data: [<?php echo $gender1; ?>]
        }, {
            name: '<?php echo $newDate2;  ?>',
            data: [<?php echo $gender2;  ?>]
        }]

      });
     });

     });

これが私が得る出力です。

{
chart: {
renderTo: 'container',
height: 220,
type: 'column'
},
 title: {
 text: ''
 },
 xAxis: {
 categories: ['apples'],
 lineWidth: 0,
 tickWidth: 0,
 },
 yAxis: {
 min: 0,
 title: {
 text: ''
 },
 stackLabels: {
 enabled: true,
 style: {
 fontWeight: 'bold',

}
}
},
legend: {
align: 'left',
x: 0,
verticalAlign: 'left',
y: 15,
floating: true,
backgroundColor: 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function () {
return '<b>' + this.x + '</b><br/>' + this.series.name + ': ' + this.y + '<br/>' +
'Total: ' + this.point.stackTotal;
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: 'white'
}
}
},
        series: [{
            name: '19-01-2013 ',
            data: [57]
        }, {
            name: '18-01-2013',
            data: [21]
        }, {
            name: '17-01-2013',
            data: [34]
        }]

        });
    });

});
4

1 に答える 1

0

だから私はそれを働かせました。私は基本的にコードを段階的に追加して、どこが壊れているかを確認しました...うまくいきました。何が起こるかわかりませんが、コードは次のとおりです。

<?php 

require_once 'config.php';

$response = file_get_contents('https://graph.facebook.com/'.FACEBOOK_PAGE_ID.'/insights    /page_views?access_token='.FACEBOOK_ACCESS_TOKEN);
$page = json_decode($response);

if ($page && $page->data) {

$test = $page->data[0]->values[2]->end_time; $newDate = date("d-m-Y", strtotime($test));  $newDate;
$gender = $page->data[0]->values[2]->value;  $gender;

$test2 = $page->data[0]->values[1]->end_time;  $newDate1 = date("d-m-Y", strtotime($test2)); $newDate1;
$gender1 = $page->data[0]->values[1]->value;  $gender1;

$test3 = $page->data[0]->values[0]->end_time;  $newDate2 = date("d-m-Y", strtotime($test3));  $newDate2;
$gender2 = $page->data[0]->values[0]->value;  $gender2;


}
header('Content-Type: application/json');

?>
 {
chart: {
renderTo: 'container',
height: 220,
type: 'column'
},
title: {
text: ''
},
xAxis: {
categories: ['Page Views'],
lineWidth: 0,
tickWidth: 0,
},
yAxis: {
min: 0,
title: {
text: ''
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',

}
}
},
legend: {
align: 'left',
x: 0,
verticalAlign: 'left',
y: 0,
floating: true,
backgroundColor: 'black',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function () {
return '<b>' + this.x + '</b><br/>' + this.series.name + ': ' + this.y + '<br/>' +
'Total: ' + this.point.stackTotal;
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: 'white'
}
}
},
series: [{
name: '<?php echo $newDate; ?> ',
data: [<?php echo  $gender; ?>]
}, {
name: '<?php echo $newDate1; ?>',
data: [<?php echo $gender1; ?>]
}, {
name: '<?php echo $newDate2;  ?>',
data: [<?php echo  $gender2;  ?>]
}]
}
于 2013-01-23T17:12:53.663 に答える