First of all, thanks in advance for any help. I have been struggling for a couple of days trying to figure out how to hook an angular-chart object into a mysql database. I currently have the charts working with static data. I have a generic php file in my project that looks something like this:
// Create the connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully";
//the sql to run
$sql = "SELECT * FROM Test2";
//run it
$result = $conn->query($sql);
//check for results
if ($result->num_rows > 0) {
//create an array
$dataarray[] = array();
//loop em
while($row =mysqli_fetch_assoc($result)) {
$dataarray[] = $row;
}
//make em json
echo json_encode($dataarray);
}
//} else {
// echo "0 results";
//}
//close out our connection
$conn->close();
?>
This works fine. This table returns a couple of rows with the headers Name and Value. Nothing but test data at this time.
In my html/javascript, I have the following:
<script>
angular.module("ChartApp", ["chart.js"]).controller("PieCtrl", function ($scope, $http) {
$http.get('./GetTestData.php').
success(function(data) {
$scope.records = data;
});
$scope.labels = ["Download Sales", "In-Store Sales", "Mail-Order Sales"];
$scope.data = [300, 500, 100];
});
</script>
I am not really sure where to go from here. Any help would be appreciated.