When I try to select an option from the list of districts the onchange run the following method:
showAgeDistributionGraph: function() {
let e = document.getElementById("TxtAgeGroup");
let txtAgeGroup = e.options[e.selectedIndex].value;
let url = 'backend/core/loadCasesByAgeGroup.php';
var jsonData = $.ajax({
url: url,
data: {
ds: txtAgeGroup
},
dataType: 'json',
}).done(function(jsonData) {
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
drawChart(jsonData);})
});
google.charts.load('current', {
packages: ['corechart']
}).then(function () {
drawChart(jsonData);
});
}
Once the above code is processed the drawChart function is executed
function drawChart(jsonData){
var data = google.visualization.arrayToDataTable([
jsonData
], false);
console.log(jsonData);
var options = {
title: 'Cases By Age Group',
width: 900,
height: 400,
bar: {groupWidth: "80%"},
legend: { position: "bottom" },
};
var chart = new google.visualization.ColumnChart(document.getElementById('chartContainer'));
chart.draw(data, options);
}
The PHP code which is executed in the background is the following:
// STATISTICS (GRAPHS)
public function districtPopulationGraph($ds)
{
$sql = "call `new_CasesAgeDistributionChart`(?);";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$ds]);
if ($stmt->rowCount()>0)
{
$data[] = ["Age","Total Clients"];
while ($record = $stmt->fetch())
{
// UPDATE TOTALS
$data[] = ["GroupA",$record['16-17']];
$data[] = ["GroupB",$record['18-29']];
$data[] = ["GroupC",$record['30-49']];
$data[] = ["GroupD",$record['50-64']];
$data[] = ["GroupE",$record['65+']];
}
$data_for_chart = json_encode($data, JSON_NUMERIC_CHECK);
return $data_for_chart;
}
// Output returned by $data_for_chart is [["Age","Total Clients"],["GroupA","24"],["GroupB","251"],["GroupC","576"],["GroupD","407"],["GroupE","659"]]
The problem is that the Chart is giving an error of: Uncaught (in promise) Error: Column header row must be an array.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
https://www.javascript.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.