Hello Everyone,
I am trying to learn php along with Dojo. So I am testing how to create a bar graph from data in my mysql database. However, I am having a problem. I can't seem to be able to read the data. I am posting the code below so you guys can see how far I have made on this. My db (brazil) is very simple with 2 tables (inca, ac) and each table has 3 columns (participantsEnrolled, participantsExpected, participantsUnassigned). I am not sure what I am doing wrong. I was able to create the graph declaring the data, but I would like to create the graph dinamically from the db. I appreciate any help. Thanks.
<!DOCTYPE html>
<html >
<head>
<h2 align="center">Bar Graphs</h2><br>
<?php
$con = mysql_connect("localhost", "test", "test") or die('Sorry, could not connect to database server');
mysql_select_db("brazil", $con) or die('Sorry, could not connect to database');
//participants enrolled
$query1 = "SELECT inca.participantsEnrolled, ac.participantsEnrolled from inca, ac";
$result = mysql_query($query) or die ('Could not find brazil');
$enrolled = mysql_fetch_array($result) or die ('could not retrieve the record');
//participants expected
query2 = "SELECT inca.participantsExpected, ac.participantsExpected from inca, ac";
$result2 = mysql_query($query2) or die ('Could not find brazil');
$expected = mysql_fetch_array($result2) or die ('could not retrieve the record');
?>
<link rel="stylesheet" type="text/css"
href="./dijit/themes/claro/claro.css" />
<script>dojoConfig = {parseOnLoad: true}</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.8.1/dojo/dojo.js"
data-dojo-config="async: true"></script>
<?php require_once 'c:/wamp/www/recipe/dojoTesting/bardb.php';?>
<script>require(["dojox/charting/Chart", "dojox/charting/axis2d/Default", "dojox/charting/plot2d/Bars", "dojox/charting/plot2d/Markers", "dojo/ready"],
function(Chart, Default, Bars, Markers, ready){
ready(function(){
var dataEnrolled = {items: ($enrolled)};
var dataExpected = {items: ($expected)};
// <?php require_once 'c:/wamp/www/recipe/dojoTesting/bardb.php'; fquery2(); ?>]};
var chart1 = new Chart("simplechart", {
title: "Participants (Enrolled X Expected)",
titlePos: "top",
titleGap: 25,
titleFont: "normal normal normal 20pt Tahoma",
titleFontColor: "black"
});
//chart1.setTheme(tundra);
chart1.addPlot("default", {type: Bars,markers:true,gap:5});
chart1.addAxis("x", {stroke:"black",font:"normal normal bold 12pt Tahoma"});
chart1.addAxis("y", {stroke:"black", font:"normal normal bold 12pt Tahoma", vertical: true,labels:[{value:0, text:""}, {value:1, text:"INCA"},
{value:2, text:"AC"}], rotation:20});
chart1.addSeries("Series A", dataEnrolled, {fill:"#3399FF"});
chart1.addSeries("Series B", dataExpected, {fill:"#123456"});
chart1.render();
});
});</script>
</head>
<body class="Wetland">
<div id="simplechart" style="width: 600px; height: 500px; margin: 10px auto 10px auto;"></div>
</body>
</html>