Can't show stacked columns dynamic json data - php

Hi all i'm looking for help creating a test chart with dynamic data in php.
In first place i create the graph witout problem.
window.onload = function () {
chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title:{
text: "Gasto Proyectado (neto)"
},
axisX: {
interval: 1,
intervalType: "month",
valueFormatString: "MM/YYYY"
},
axisY: {
suffix: "",
valueFormatString: "$#,###"
},
toolTip: {
shared: true
},
legend: {
reversed: true,
verticalAlign: "center",
horizontalAlign: "right",
cursor: "pointer",
itemclick: toggleDataSeries
},
data:[
<?php
$gastoMensualProyectado = Helper::gastoMensualProyectado();
//var_dump($gastoMensualProyectado);
//die();
$controlCostoN1= array();
foreach ($gastoMensualProyectado as $key => $value) {
$controlCostoN1[]= $value['name'];
}
$controlCostoN1 = array_unique($controlCostoN1);
$output = '';
foreach ($controlCostoN1 as $indice => $name) {
$output .= '{
type: "stackedColumn",
name: "'.$name.'",
showInLegend: true,
xValueFormatString: "MMM, YYYY",
yValueFormatString: "$#,###",
dataPoints:[';
foreach ($gastoMensualProyectado as $key => $value) {
if ($name == $value['name']){
$output.='{ x:'.$value['x'].', y:'.$value['y'].'},';
}
}
$output .=']},';
}
$output = substr($output,0,-3);
print $output;
?>
]
}]
});
chart.render();
Then i want to put new data calling a php file that respond with json_encode function
$dps = array();
$i=0;
$header = '';
foreach ($controlCostoN1 as $indice => $name) {
//$val[$i] = 'type: "stackedColumn",name: "'.$name.'",showInLegend: true,xValueFormatString: "MMM, YYYY",yValueFormatString: "$#,###",dataPoints:';
//var_dump($name);
foreach ($gastoMensualProyectado as $key => $value) {
// echo $name;
if ($name == $value['name']){
$dps[][$name] = $value;
/*
$header .= '{
type: "stackedColumn",
name: "'.$name.'",
showInLegend: true,
yValueFormatString: "#,##0 MW",
dataPoints: ';
//$points[] = '{ x:'.$value['x'].', y:'.$value['y'].'},';
//$dps[] = [ "x" => $value['x'], "y" => $value['y'] ];
.json_encode($value, JSON_NUMERIC_CHECK).'
},';
*/
}
}
}
// $output = substr($output,0,-3);
echo json_encode($dps);`
And then try to refresh the data in the graph when change a select but the grph change with no columns at all.
` $('#idPresupuesto').change(function(event) {
var dps = [];
var names = [];
var response;
$.getJSON("acciones/obtenerDatosStackedColumns.json.php", { idPresupuesto: $(this).val() } ,function(data) {
// console.log(data);
// console.log("swasaddsaasd");
$.each(data, function(key, value){
// dataPoints.push({x: value[0], y: parseInt(value[1])});
// console.log(value.first());
// console.log(value[Object.keys(value)[0]].name);
// value.map()
jQuery.map( value , function( n, i){
if(jQuery.inArray(n.name,names) < 0){
names.push(n.name);
//console.log(n.name);
}
});
});
$.each(data, function(key, value){
// console.log(key);
jQuery.map( value , function( n, i){
// console.log(n.x + " "+n.y);
dps.push({x: n.x, y: parseInt(n.y)});
// console.log();
});
});
console.log(dps);
// console.log(names);
// console.log(names.length);
var chart = new CanvasJS.Chart("chartContainer",{
title:{
text:"Presupuesto"
},
animationEnabled: true,
data: [{
dataPoints : dps,
}]
});
chart.render();
});
});`
the json response is:
[{
"Alimentaci\u00f3n": {
"idOrdenCompra": 7,
"x": "new Date(2019, 2)",
"y": 1361340,
"name": "Alimentaci\u00f3n"
}
}, {
"Alimentaci\u00f3n": {
"idOrdenCompra": 146,
"x": "new Date(2019, 2)",
"y": 60000,
"name": "Alimentaci\u00f3n"
}
}, {
"Equipos": {
"idOrdenCompra": 125,
"x": "new Date(2019, 1)",
"y": 350500,
"name": "Equipos"
}
}, {
"Equipos": {
"idOrdenCompra": 29,
"x": "new Date(2019, 3)",
"y": 95014016,
"name": "Equipos"
}
}, {
"Equipos": {
"idOrdenCompra": 141,
"x": "new Date(2019, 3)",
"y": 2743908,
"name": "Equipos"
}
}, {
"Equipos de Protecci\u00f3n Personal": {
"idOrdenCompra": 1,
"x": "new Date(2019, 1)",
"y": 26179454,
"name": "Equipos de Protecci\u00f3n Personal"
}
}, {
"Equipos de Protecci\u00f3n Personal": {
"idOrdenCompra": 18,
"x": "new Date(2019, 3)",
"y": 8599651,
"name": "Equipos de Protecci\u00f3n Personal"
}
}, {
"Equipos de Protecci\u00f3n Personal": {
"idOrdenCompra": 84,
"x": "new Date(2019, 3)",
"y": 3233271,
"name": "Equipos de Protecci\u00f3n Personal"
}
}, {
"Materiales": {
"idOrdenCompra": 4,
"x": "new Date(2019, 2)",
"y": 12975104,
"name": "Materiales"
}
}, {
"Materiales": {
"idOrdenCompra": 14,
"x": "new Date(2019, 2)",
"y": 30393814,
"name": "Materiales"
}
}, {
"Materiales": {
"idOrdenCompra": 82,
"x": "new Date(2019, 2)",
"y": 30014590,
"name": "Materiales"
}
}, {
"Saldos Gastos Generales": {
"idOrdenCompra": 3,
"x": "new Date(2019, 2)",
"y": 4657962,
"name": "Saldos Gastos Generales"
}
}, {
"Saldos Gastos Generales": {
"idOrdenCompra": 16,
"x": "new Date(2019, 3)",
"y": 107923647,
"name": "Saldos Gastos Generales"
}
}, {
"Saldos Gastos Generales": {
"idOrdenCompra": 86,
"x": "new Date(2019, 3)",
"y": 80498702,
"name": "Saldos Gastos Generales"
}
}, {
"Herramientas": {
"idOrdenCompra": 16,
"x": "new Date(2019, 3)",
"y": 5056052,
"name": "Herramientas"
}
}, {
"Herramientas": {
"idOrdenCompra": 92,
"x": "new Date(2019, 4)",
"y": 2192715,
"name": "Herramientas"
}
}, {
"Mano de Obra": {
"idOrdenCompra": 19,
"x": "new Date(2019, 1)",
"y": 16748410,
"name": "Mano de Obra"
}
}, {
"Mano de Obra": {
"idOrdenCompra": 91,
"x": "new Date(2019, 3)",
"y": 1962698,
"name": "Mano de Obra"
}
}]
Actually the first graph render good but when i try to update data show me an empty chart.

I fixed it changing the json content of date
"x": "new Date(2019, 3)",
to
"x": "2019, 3",
and then apply to this line the object Date
$output.='{ x:new Date('.$value['x'].'), y:'.$value['y'].'},';
the the graph works great an dynamically!
hope this help to somebody.

Related

How to access JSON object values using vue steps?

This is step 1. These are the input boxes i want to type. This is the function I created to point each value to input boxes:
getmyEditor: function(){
this.chartType = this.options.chart.type;
this.backgroundColor = this.options.chart.backgroundColor;
this.borderColor = this.options.chart.borderColor;
this.borderWidth = this.options.chart.borderWidth;
this.height = this.options.chart.height;
this.options.xAxis.plotLines = [{
value: this.xPlotLinesvalue,
label: {
text: this.xPlotLinesText,
align: 'center',
style: {
color: 'gray'
}
}}];
Above code i created to access object values. how to apply this values added
text boxes?
{"chart": {
"type": "pie",
"backgroundColor": "#FFFFFF",
"borderColor": "#000",
"borderWidth": 0,
"height": 300,
"inverted": false,
"plotBackgroundColor": "#FFFFFF",
"plotBorderColor": "#FFFFFF",
"plotBorderWidth": 1,
"style": {
"fontFamily": "Open Sans"
},
"polar": ""
},
"title": {
"text": "Title",
"x": -20
},
"table": {
"text": ""
},
"xAxis": {
"max": null,
"categories": [],
"title": {
"text": ""
},
"plotLines": [
{
"value": 0,
"width": 0,
"color": "red",
"label": {
"text": "",
"align": "center",
"style": {
"color": "gray"
}
}
}
]
},
"yAxis": {
"title": {
"text": ""
},
"categories": [],
"min": null,
"max": null,
"plotLines": [
{
"value": 0,
"width": 0,
"color": "red",
"label": {
"text": "",
"align": "center",
"style": {
"color": "gray"
}
}
}
]
},
"zAxis": "",
"tooltip": {
"valueDecimals": 0,
"valuePrefix": "",
"valueSuffix": "",
"padding": 8
},
"legend": {
"enabled": true,
"layout": "vertical",
"align": "right",
"verticalAlign": "middle",
"borderWidth": 0
},
"credits": {
"enabled": false
},
"plotOptions": {
"series": {
"color": "#582b6e",
"stacking": "",
"point": {
"events": {}
}
},
"scatter": {
"marker": {
"radius": 4,
"states": {
"hover": {
"enabled": true,
"lineColor": "rgb(100,100,100)"
}
}
},
"states": {
"hover": {
"marker": {
"enabled": false
}
}
},
"tooltip": {
"headerFormat": "<b>{series.name}</b><br>",
"pointFormat": "{point.x} , {point.y} ",
"x_unit": "",
"y_unit": ""
}
}
},
"series": [
{
"name": "Brands",
"colorByPoint": true,
"data": [
{
"name": "IE",
"y": 56.33
},
{
"name": "Chrome",
"y": 24.03,
"sliced": true,
"selected": true
},
{
"name": "Firefox",
"y": 10.38
},
{
"name": "Safari",
"y": 4.77
},
{
"name": "Opera",
"y": 0.91
},
{
"name": "Other",
"y": 0.2
}
]
}
],
"lang": {
"noData": "NO DATA AVAILABLE!"
},
"noData": {
"style": {
"fontWeight": "bold",
"fontSize": "15px",
"color": "#303030"
}
}
}
I'm trying to access (point to text boxes) this object using vue, but it's not working yet. How to do that correctly? I point each object value using this vue function inside method.
This is i want final output: This object view inside textarea if i change text area object value then that value will going to above input boxes.

How to return JSON objects with Array php

I have this php code to return the Array from a JSON file how ever I am not able to return the objects (The Airport info structure) as well the Arrivals etc.
Apologies if this is not very clear I am fairly new to this.
Code:
$fxml_response = $client->request('GET', 'AirportBoards', ['query' => $queryParams]);
try {
$body = json_decode($fxml_response->getBody(), true);
if ($fxml_response->getStatusCode() == 200 && !array_key_exists('error', $body)) {
foreach (['arrivals', 'departures', 'enroute', 'scheduled',] as $board) {
if($body['AirportBoardsResult'][$board]) {
$boardFlights = $body['AirportBoardsResult'][$board]['flights'];
$response[$board] = $boardFlights;
}
}
} else {
$response['error'] = $body['error'];
}
} catch (Exception $e) {
echo json_encode(['error' => 'Failed to retrieve Airport Board details.']);
}
// Send back the data
header('Content-Type: application/json');
echo json_encode($response);
Json:
{
"AirportBoardsResult": {
"airport": "NZAP",
"airport_info": {
"airport_code": "NZAP",
"name": "Taupo",
"elevation": 1335.0,
"city": "Taupo",
"state": "",
"longitude": 176.084444,
"latitude": -38.739723,
"timezone": ":Pacific/Auckland",
"country_code": "NZ",
"wiki_url": "https://en.wikipedia.org/wiki/Taupo_Airport",
"alternate_ident": "TUO"
},
"arrivals": {
"num_flights": 6,
"next_offset": -1,
"flights": [{
"ident": "SDA806",
"faFlightID": "SDA806-1528092600-schedule-0000",
"airline": "SDA",
"airline_iata": "S8",
"flightnumber": "806",
"tailnumber": "ZK-PLV",
"type": "Form_Airline",
"blocked": false,
"diverted": false,
"cancelled": false,
"origin": {
"code": "NZWN",
"city": "Wellington",
"alternate_ident": "WLG",
"airport_name": "Wellington Int'l"
},
"destination": {
"code": "NZAP",
"city": "Taupo",
"alternate_ident": "TUO",
"airport_name": "Taupo"
},
"filed_ete": 3480,
"route": "KADNU1Q KAPTI WNAP2",
"filed_altitude": 210,
"display_filed_altitude": "21,000 feet",
"filed_airspeed_kts": 250,
"distance_filed": 191,
"filed_departure_time": {
"epoch": 1528265400,
"tz": "NZST",
"dow": "Wednesday",
"time": "06:10PM",
"date": "06/06/2018",
"localtime": 1528308600
},
"estimated_departure_time": {
"epoch": 1528265889,
"tz": "NZST",
"dow": "Wednesday",
"time": "06:18PM",
"date": "06/06/2018",
"localtime": 1528309089
},
"actual_departure_time": {
"epoch": 1528265889,
"tz": "NZST",
"dow": "Wednesday",
"time": "06:18PM",
"date": "06/06/2018",
"localtime": 1528309089
},
"departure_delay": 489,
"filed_arrival_time": {
"epoch": 1528268880,
"tz": "NZST",
"dow": "Wednesday",
"time": "07:08PM",
"date": "06/06/2018",
"localtime": 1528312080
},
"estimated_arrival_time": {
"epoch": 1528269502,
"tz": "NZST",
"dow": "Wednesday",
"time": "07:18PM",
"date": "06/06/2018",
"localtime": 1528312702
},
"actual_arrival_time": {
"epoch": 1528269180,
"tz": "NZST",
"dow": "Wednesday",
"time": "07:13PM",
"date": "06/06/2018",
"localtime": 1528312380
},
"arrival_delay": 300,
"status": "Arrived",
"progress_percent": 100,
"aircrafttype": "PC12",
"full_aircrafttype": "L/PC12",
"adhoc": false
}]
};
Add the airport info to the result after the loop.
if ($fxml_response->getStatusCode() == 200 && !array_key_exists('error', $body)) {
foreach (['arrivals', 'departures', 'enroute', 'scheduled',] as $board) {
if($body['AirportBoardsResult'][$board]) {
$boardFlights = $body['AirportBoardsResult'][$board]['flights'];
$response[$board] = $boardFlights;
}
}
$response['airport_info'] = $body['AirportBoardsResult']['airport_info'];
}

CanvasJS chart not rendering properly when using json data returned from php

Hi I am trying to use CanvasJS to render an area chart using JSON data returned from php. The chart renders but does not have any Values and is just blank apart from the axis's.
Something must be wrong with the JSON output but i cant see why?
The Javascript:
$(document).ready(function(){
$("#click").click(function(){
$.ajax({
type: "POST",
url: "data.php",
dataType: 'json',
success: function(data) {
loadChart(data);
}
});
});
});
function loadChart(response) {
console.log(response);
var chart = new CanvasJS.Chart("chartContainer",
{
title: {
text: "Email Analysis"
},
animationEnabled: true,
axisX:{
interval: 3
// labelAngle : 30,
// valueFormatString: "HHmm'hrs'"
},
axisY: {
title: "kWH"
},
legend: {
verticalAlign: "bottom",
horizontalAlign: "center"
},
data: response
});
chart.render();
}
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
<input id="click" type="button">
The php script which returns the JSON:
$begin = new DateTime( '2017-01-01' );
$end = new DateTime( '2017-01-31' );
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);
$data[0] = array(
'name'=> "Electricy",
'showInLegend' => true,
'legendMarkerType' => "square",
'type' => "area",
'color' => "rgba(40,175,101,0.6)",
'markerSize' => 0,
'xValueType' => "dateTime",
);
foreach ( $period as $dt ){
$data[0]['dataPoints'][] = array('x' => $dt->getTimestamp(), 'y' => 10);
}
$data[1] = array(
'name'=> "Gas",
'showInLegend' => true,
'legendMarkerType' => "square",
'type' => "area",
'color' => "rgba(40,175,101,0.6)",
'markerSize' => 0,
'xValueType' => "dateTime",
);
foreach ( $period as $dt ){
$data[1]['dataPoints'][] = array('x' => $dt->getTimestamp(), 'y' => 20);
}
$data = json_encode($data);
echo $data;
die();
It outputs the following JSON:
[{
"name": "Electricy",
"showInLegend": true,
"legendMarkerType": "square",
"type": "area",
"color": "rgba(40,175,101,0.6)",
"markerSize": 0,
"xValueType": "dateTime",
"dataPoints": [{
"x": 1483228800,
"y": 10
}, {
"x": 1483315200,
"y": 10
}, {
"x": 1483401600,
"y": 10
}, {
"x": 1483488000,
"y": 10
}, {
"x": 1483574400,
"y": 10
}, {
"x": 1483660800,
"y": 10
}, {
"x": 1483747200,
"y": 10
}, {
"x": 1483833600,
"y": 10
}, {
"x": 1483920000,
"y": 10
}, {
"x": 1484006400,
"y": 10
}, {
"x": 1484092800,
"y": 10
}, {
"x": 1484179200,
"y": 10
}, {
"x": 1484265600,
"y": 10
}, {
"x": 1484352000,
"y": 10
}, {
"x": 1484438400,
"y": 10
}, {
"x": 1484524800,
"y": 10
}, {
"x": 1484611200,
"y": 10
}, {
"x": 1484697600,
"y": 10
}, {
"x": 1484784000,
"y": 10
}, {
"x": 1484870400,
"y": 10
}, {
"x": 1484956800,
"y": 10
}, {
"x": 1485043200,
"y": 10
}, {
"x": 1485129600,
"y": 10
}, {
"x": 1485216000,
"y": 10
}, {
"x": 1485302400,
"y": 10
}, {
"x": 1485388800,
"y": 10
}, {
"x": 1485475200,
"y": 10
}, {
"x": 1485561600,
"y": 10
}, {
"x": 1485648000,
"y": 10
}, {
"x": 1485734400,
"y": 10
}]
}, {
"name": "Gas",
"showInLegend": true,
"legendMarkerType": "square",
"type": "area",
"color": "rgba(40,175,101,0.6)",
"markerSize": 0,
"xValueType": "dateTime",
"dataPoints": [{
"x": 1483228800,
"y": 20
}, {
"x": 1483315200,
"y": 20
}, {
"x": 1483401600,
"y": 20
}, {
"x": 1483488000,
"y": 20
}, {
"x": 1483574400,
"y": 20
}, {
"x": 1483660800,
"y": 20
}, {
"x": 1483747200,
"y": 20
}, {
"x": 1483833600,
"y": 20
}, {
"x": 1483920000,
"y": 20
}, {
"x": 1484006400,
"y": 20
}, {
"x": 1484092800,
"y": 20
}, {
"x": 1484179200,
"y": 20
}, {
"x": 1484265600,
"y": 20
}, {
"x": 1484352000,
"y": 20
}, {
"x": 1484438400,
"y": 20
}, {
"x": 1484524800,
"y": 20
}, {
"x": 1484611200,
"y": 20
}, {
"x": 1484697600,
"y": 20
}, {
"x": 1484784000,
"y": 20
}, {
"x": 1484870400,
"y": 20
}, {
"x": 1484956800,
"y": 20
}, {
"x": 1485043200,
"y": 20
}, {
"x": 1485129600,
"y": 20
}, {
"x": 1485216000,
"y": 20
}, {
"x": 1485302400,
"y": 20
}, {
"x": 1485388800,
"y": 20
}, {
"x": 1485475200,
"y": 20
}, {
"x": 1485561600,
"y": 20
}, {
"x": 1485648000,
"y": 20
}, {
"x": 1485734400,
"y": 20
}]
}]
It looks like you're using an old version of the library. I've used your json data with the latest CDN version and it seems to work OK.
EDIT You are seeing hours because you are generating Unix timestamps in PHP (which are in seconds).
To convert to a javascript timestamp multiply the value by 1000: $dt->getTimestamp() * 1000
I've updated this demo with the json data multiplied by 1000 http://jsbin.com/nezigexilu/1/edit?html,output
<script src="http://canvasjs.com/assets/script/canvasjs.min.js"></script>

Amchart dataLoader to have drilldown dynamically

Based on this tutorial https://www.amcharts.com/kbase/using-data-loader-to-connect-charts-to-mysql-data-base/, I am able to load the data by calling a php page using dataLoader into this kind of chart https://www.amcharts.com/demos/combined-bullet-column-line-chart/
My requirement:
When click on the column in the chart, it needs to call the another php file to fetch data with a different query based on the selection in the chart (that will be used as a where condition in query).
I tried something with the below code, but nothing works
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"dataDateFormat": "MM-YYYY",
"precision": 2,
"valueAxes": [{
"id": "v1",
"title": "Average",
"position": "left",
"autoGridCount": false,
"labelFunction": function(value) {
return Math.round(value) ;
}
}, {
"id": "v2",
"title": "Maximum",
"gridAlpha": 0,
"position": "right",
"autoGridCount": false
}],
"graphs": [{
"id": "g3",
"valueAxis": "v1",
"lineColor": "#e1ede9",
"fillColors": "#e1ede9",
"fillAlphas": 1,
"type": "column",
"title": "Actual Average",
"valueField": "Average",
"clustered": false,
"columnWidth": 12,
"legendValueText": "[[value]]",
"balloonText": "[[title]]<br /><b style='font-size: 130%'>[[value]]</b>"
}, {
"id": "g4",
"valueAxis": "v1",
"lineColor": "#62cf73",
"fillColors": "#62cf73",
"fillAlphas": 1,
"type": "column",
"title": "Actual Maximum",
"valueField":"Maximum",
"clustered": false,
"columnWidth":8,
"legendValueText": "[[value]]",
"balloonText": "[[title]]<br /><b style='font-size: 130%'>[[value]]</b>"
}, {
"id": "g1",
"valueAxis": "v2",
"bullet": "round",
"bulletBorderAlpha": 1,
"bulletColor": "#FFFFFF",
"bulletSize": 5,
"hideBulletsCount": 50,
"lineThickness": 2,
"lineColor": "#20acd4",
"type": "smoothedLine",
"title": "Target Average",
"useLineColorForBulletBorder": true,
"valueField": "Average",
"balloonText": "[[title]]<br /><b style='font-size: 130%'>[[value]]</b>"
}, {
"id": "g2",
"valueAxis": "v2",
"bullet": "round",
"bulletBorderAlpha": 1,
"bulletColor": "#FFFFFF",
"bulletSize": 5,
"hideBulletsCount": 50,
"lineThickness": 2,
"lineColor": "#e1ede9",
"type": "smoothedLine",
"dashLength": 5,
"title": "Target Maximum",
"useLineColorForBulletBorder": true,
"valueField": "Maximum",
"balloonText": "[[title]]<br /><b style='font-size: 130%'>[[value]]</b>"
}],
"chartScrollbar": {
"graph": "g1",
"oppositeAxis": false,
"offset": 30,
"scrollbarHeight": 50,
"backgroundAlpha": 0,
"selectedBackgroundAlpha": 0.1,
"selectedBackgroundColor": "#888888",
"graphFillAlpha": 0,
"graphLineAlpha": 0.5,
"selectedGraphFillAlpha": 0,
"selectedGraphLineAlpha": 1,
"autoGridCount": true,
"color": "#AAAAAA"
},
"chartCursor": {
"pan": true,
"valueLineEnabled": true,
"valueLineBalloonEnabled": true,
"cursorAlpha": 0,
"valueLineAlpha": 0.2
},
"categoryField": "Month",
"categoryAxis": {
"parseDates": true,
"dashLength":1,
"minorGridEnabled": true
},
"legend": {
"useGraphSettings": true,
"position": "top"
},
"balloon": {
"borderThickness": 1,
"shadowAlpha": 0
},
"export": {
"enabled": true
},
//"dataProvider":[{"Month":"01-2016","Average":43.63888889,"Maximum":50.06222222,"Province":"Riyadh"},{"Month":"02-2016","Average":46.11888889,"Maximum":52.78222222,"Province":"Eastern Province"},{"Month":"03-2016","Average":48.33740741,"Maximum":49.78555556,"Province":"Eastern Province"},{"Month":"04-2016","Average":39.37629630,"Maximum":41.25111111,"Province":"Eastern Province"},{"Month":"05-2016","Average":43.98481481,"Maximum":54.25000000,"Province":"Eastern Province"},{"Month":"06-2016","Average":49.68888889,"Maximum":71.53777778,"Province":"Riyadh"},{"Month":"07-2016","Average":39.92333333,"Maximum":44.52111111,"Province":"Eastern Province"},{"Month":"08-2016","Average":48.72370370,"Maximum":58.98222222,"Province":"Makkah"},{"Month":"09-2016","Average":34.18370370,"Maximum":43.88111111,"Province":"Makkah"},{"Month":"10-2016","Average":48.77962963,"Maximum":63.22333333,"Province":"Makkah"}]
"dataLoader": {"url": "bed-turnover.php"}
});
chart.addListener("clickGraphItem", function (event) {
// let's look if the clicked graph item had any subdata to drill-down into
// wow it has!
// let's set that as chart's
//chart.dataLoader.loadFile("bed-turnover-drill-province.php");
// event.chart.dataLoader ={"url": "bed-turnover-drill-province.php"};
// event.chart.validateData();
chart.dataLoader = { url: "bed-turnover-drill-province.php"}
//chart.validateData();
};
});
Kindly help.
Regards
You have to call the dataLoader's loadData method after you change the URL to load from the new source:
chart.addListener("clickGraphItem", function (event) {
chart.dataLoader.url = "bed-turnover-drill-province.php";
chart.dataLoader.loadData();
};

Process a jQuery $Post with php?

I need to process this with php (note that the data being sent is JSON):
$.post("calculate.php", existingJsonData,
function(data) {
//alert("Data Loaded: " + data);
console.log("test data", data.values);
});
The existingJsonData is formatted like this:
{
"object1": {
"object11": {"x": "10", "y": "20", "z": "30"},
"object12": {"x": "40", "y": "50", "z": "60"},
"object13": {"x": "70", "y": "80", "z": "90"}
},
"object2": {
"object21": {"x": "100", "y": "200", "z": "300"},
"object22": {"x": "400", "y": "500", "z": "600"},
"object23": {"x": "700", "y": "800", "z": "900"}
}
}
The php needs to add 1 to each of the x's in "object2".
This one adds 1 to each of the x's in object 2 and alerts you the incremented values
<?php
if ($_POST){
ob_clean();
$objects = $_POST['object2'];
foreach($objects as $a => $subObject) {
$objects[$a] = $subObject['x'] + 1;
}
die(json_encode((object) $objects));
}
?>
<script>
var existingJsonData= $.parseJSON('{ "object1": { "object11": {"x": "10", "y": "20", "z": "30"}, "object12": {"x": "40", "y": "50", "z": "60"}, "object13": {"x": "70", "y": "80", "z": "90"} }, "object2": { "object21": {"x": "100", "y": "200", "z": "300"}, "object22": {"x": "400", "y": "500", "z": "600"}, "object23": {"x": "700", "y": "800", "z": "900"}}}');
$.post("<?php echo $_SERVER['PHP_SELF']; ?>", existingJsonData,
function(data) {
var data = $.parseJSON(data);
$.each(data, function(a,b){
alert(a+' : '+b);
});
});
</script>
demo

Categories