我想在这个javascript图表中显示我的php表的值。 var d1 d2和d3的脚本值只是dummy / demo。我想让月份沿x轴运行。我只是不知道如何将我的PHP与js合并。
我的表(PHP)
<?php if ($bymonths = $db->get_results("SELECT * from vw_dash_bymonth_2012"));
foreach ($bymonths as $month) {
$startmonth = date('m-d-Y', strtotime('first day of this month', $month->realdate));
$endmonth = date('m-d-Y', strtotime('last day of this month', $month->realdate));
echo "<tr>
<td><a href=bymonth.php?month={$month->month1}>" . date('F', $month->realdate) . "</a> " . date('Y', $month->realdate) . "</td>
<td>" . $month->gallons . "</td>
<td>" . $month->service . "</td>
<td>" . $month->average . "</td></tr>";
}
?>
示例JS
<script type="text/javascript">
$(function () {
var d1 = [];
for (var i = 0; i < 14; i += 0.5)
d1.push([i, Math.sin(i)]);
var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
var d3 = [];
for (var i = 0; i < 14; i += 0.5)
d3.push([i, Math.cos(i)]);
$.plot($("#multiple"), [
{
label: "Gallons",
data: d1,
lines: { show: true },
points: { show: true, fill: true }
},
{
label: "Services",
data: d2,
lines: { show: true },
points: { show: true, fill: true }
},
{
label: "Average",
data: d3,
lines: { show: true },
points: { show: true, fill: true }
}
]);
});
</script>