我有以下代码。 我从其他页面通过get方法获得时间到feedback.php。
现在我需要将此值从feedback.php传递到此行的chart.js ['你所用的时间是',时间] 然后它将在feedback.php页面上显示图表。我怎样才能完成这件事?
feedback.php
<script src="chart.js"></script>
<div id="chart_div"></div>
<div id="chart_div"></div>
**<?php $time= $_GET["sec"];?><br>**
chart.js之
var data = google.visualization.arrayToDataTable([
['Time', 'Time taken by worker'],
['Worker 1 ', 200],
['Worker 2', 150],
['Worker 3', 300],
['Worker 4', 160],
['Worker 5', 140],
['Time taken by you is', time]
]);
答案 0 :(得分:1)
尝试下面
在加载chart.js
之前定义时间变量<script>
var TIME_VAR = '<?=$_GET["sec"];?>';
</script>
然后加载 <script src="chart.js"></script>
在 chart.js 中,您可以使用 TIME_VAR
var data = google.visualization.arrayToDataTable([
['Time', 'Time taken by worker'],
['Worker 1 ', 200],
['Worker 2', 150],
['Worker 3', 300],
['Worker 4', 160],
['Worker 5', 140],
['Time taken by you is',TIME_VAR]
]);