jquery - how to draw multiple googlechart from different datatable in one php file? -
i want draw few charts different datatables. datatables queries in 1 php file called ajax.php.
this code:
//job post salary function jobsalary(){ global $db; //query location total post $sql = 'select lcs.salaryrange_id, count(ljj.job_id) count, lcs.salaryrange_item {local_jobs_job} ljj inner join {local_cv_salaryrange} lcs on ljj.job_salaryrangeid = lcs.salaryrange_id job_type = 0 group lcs.salaryrange_item'; //get query record $data = $db->get_records_sql($sql); //put query 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 job's category function jobcategory(){ global $db; //query job's category total post $sql = 'select ljc.category_id, count(ljj.job_id) count, ljc.category_group {local_jobs_job} ljj inner join {local_jobs_category} ljc on ljj.job_categoryid = ljc.category_id ljj.job_type = 0 group ljc.category_group'; //get query record $data = $db->get_records_sql($sql); //put query 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); }
the chart drawn in php file called report.php. code:
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 location', pieslicetext: 'label', tooltip: {ishtml: true}, width: 500, height: 300, chartarea: { left:"5%",top:"20%",width:"90%",height:"90%" } }; // instantiate , draw our pie chart, passing in options. var chart = new google.visualization.piechart(document.getelementbyid('chart_div')); //draw chart chart.draw(piechartdata, optionschart); }
but, don't know how call specific function each chart using ajax call. previously, draw 1 chart using 1 datatable in ajax.php file.
as per requirement create multiple ajax files , call ajax files in 1 php file
Comments
Post a Comment