使用MySQL数据库中的数据的条形图

时间:2016-03-26 09:31:35

标签: php html

大家好,下午好 截至目前这是我所拥有的

    Database: Election2016
    Table Name: Candidate_Info
    Here is the 2 of my fields in my Table that I think is important in creating my Output 
candidatename[varchar] and numberofvotes[integer]

截至目前为止我的数据

candidatename numberofvotes
Person1            24
Person2            1

从此Scratch如何创建条形图? 我很抱歉问这个简单的问题。我只是这个东西的初学者。

我使用PHP,它将用于网站 感谢任何帮助TY

截至目前,这是我的代码

在mysql_graph_bar.php里面

<?php
include("phpgraphlib.php");
$graph=new PHPGraphLib(550,350); 
$link = mysql_connect('localhost', 'root', '')
   or die('Could not connect: ' . mysql_error());

mysql_select_db('election2016') or die('Could not select database');

$dataArray=array();

//get data from database
$sql="SELECT * from candidate_info group by position";
$result = mysql_query($sql) or die('Query failed: ' . mysql_error());
if ($result) {
  while ($row = mysql_fetch_assoc($result)) {
      $salesgroup=$row["salesgroup"];
      $count=$row["count"];
      //add to data areray
      $dataArray[$salesgroup]=$count;
  }
}

//configure graph
$graph->addData($dataArray);
$graph->setTitle("candidates");
$graph->setGradient("lime", "green");
$graph->setBarOutlineColor("black");
$graph->createGraph();
?>
在bargraph.php里面

<html>
<h3>This is where I want to display my graph</h3>
<img src="mysql_graph_bar.php" />
</html>

0 个答案:

没有答案