【发布时间】:2015-04-07 19:49:55
【问题描述】:
我正在使用 Microsoft WebMatrix 创建一个基本网站。我在 PHP 中有一个浮点值数组。我想使用这些值在 CSS 中创建一个条形图(例如,值 50.0 创建一个高度为 300 像素 50% 的条形图)。这是我正在使用的全部代码,因为没有那么多。当我在浏览器(Google Chrome 或 Internet Explorer)中运行它时,它会写入第一个 echo 语句,但不会产生任何条。如何编辑我的代码以绘制条形图?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Bar chart</title>
<style>
.bar
{
color: #00ff21;
width: 30px; //This defines the colour and width of the bars
}
</style>
</head>
<body>
<?php
echo("<p>This is my bar chart!</p>");
$values = array(50.0, 20.0, 35.0, 70.0); //This is the array of float values
for ($i = 0; $i < count($values); $i++) //This loop should create a bar for each element in the array
{
$currentHeight = 300 * $values[$i] / 100.0; ?>
<div class="bar" style="height: <?php echo($currentHeight); ?> "></div>
<?php
}
?>
</body>
【问题讨论】: