gpt4 book ai didi

php - 如何从一个php文件中的不同数据表中绘制多个googlechart?

转载 作者:行者123 更新时间:2023-12-01 05:19:18 24 4
gpt4 key购买 nike

我想从不同的数据表中绘制一些图表。数据表来自一个名为 ajax.php 的 PHP 文件中的查询。

这是代码:

//JOB POST BY SALARY
function jobsalary(){

global $DB;

//query by location total post
$sql = 'SELECT lcs.salaryrange_id, count(ljj.job_id) as count, lcs.salaryrange_item FROM {local_jobs_job} ljj INNER JOIN {local_cv_salaryrange} lcs ON ljj.job_salaryrangeid = lcs.salaryrange_id WHERE job_type = 0 GROUP BY lcs.salaryrange_item';


//get the query into record
$data = $DB->get_records_sql($sql);

//put the query into array
$rows = array();

$rows = array_map(function($item) {
return (object) ['c' => [
(object) ['v' => $item->salaryrange_item, 'f' => null],
(object) ['v' => intval($item->count), 'f' => null]
]];
}, array_values($data));


// prepare return data
$cols = [
(object) ['id' => '', 'label' => 'LABEL', 'pattern' => '', 'type' => 'string'],
(object) ['id' => '', 'label' => 'TOTAL', 'pattern' => '', 'type' => 'number'],
];


$returndata = new stdClass;
$returndata->cols = $cols;
$returndata->rows = $rows;

echo json_encode($returndata);

}

//JOB POST BY JOB'S CATEGORY
function jobcategory(){

global $DB;

//query by job's category total post
$sql = 'SELECT ljc.category_id, count(ljj.job_id) as count, ljc.category_group FROM {local_jobs_job} ljj INNER JOIN {local_jobs_category} ljc ON ljj.job_categoryid = ljc.category_id where ljj.job_type = 0 group by ljc.category_group';


//get the query into record
$data = $DB->get_records_sql($sql);

//put the query into array
$rows = array();

$rows = array_map(function($item) {
return (object) ['c' => [
(object) ['v' => $item->category_group, 'f' => null],
(object) ['v' => intval($item->count), 'f' => null]
]];
}, array_values($data));


// prepare return data
$cols = [
(object) ['id' => '', 'label' => 'LABEL', 'pattern' => '', 'type' => 'string'],
(object) ['id' => '', 'label' => 'TOTAL', 'pattern' => '', 'type' => 'number'],
];


$returndata = new stdClass;
$returndata->cols = $cols;
$returndata->rows = $rows;

echo json_encode($returndata);


}

图表是在另一个名为report.php 的php 文件中绘制的。这是代码:

 google.charts.setOnLoadCallback(drawItems);

function drawItems(){
var functionName = JSON.stringify({values:"joblocation"});
var jsonPieChartData = $.ajax({
url: "ajax.php",
contentType: "application/json",
data: "functionName",
dataType: "json",
async: false,

}).responseText;

var piechartdata = new google.visualization.DataTable(jsonPieChartData);

var optionsChart = {
//title: 'Job Posts by Location',
pieSliceText: 'label',
tooltip: {isHtml: true},
width: 500,
height: 300,
chartArea: { left:"5%",top:"20%",width:"90%",height:"90%" }
};

// Instantiate and draw our pie chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));


//draw the chart
chart.draw(piechartdata, optionsChart);

}

但是,我不知道如何使用 ajax 调用为每个图表调用特定函数。以前,我只是使用 ajax.php 文件中的一个数据表绘制一张图表。

最佳答案

根据您的要求创建多个ajax文件并在一个php文件中调用所有ajax文件

关于php - 如何从一个php文件中的不同数据表中绘制多个googlechart?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46169280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com