Amchart dataLoader to have drilldown dynamically - php

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();
};

Related

Laravel / Mongodb - How to delete a single / multiple keys from the documents

In the mongodb database I have multiple documetns and each document contain this type of data:
{
"_id": {
"$oid": "636b7f0f889929ce62194c28"
},
"id": "SK7732.1825+1",
"aff_link": "https://go.linkwi.se/z/11593-0/CD24352/?lnkurl=https%3A%2F%2Fwww.celestino.gr%2Fel-GR%2Fpanteloni-me-pietes-lefko%2Fprd%2FSK7732.1825%2F7%3Faffiliate%3Dlinkwise%26utm_source%3Dlinkwise%26utm_medium%3Dlw%26utm_campaign%3Dlw",
"availability": "Y",
"brand": "Celestino",
"color": [],
"date_add": 1667989263,
"date_upd": 1674697681,
"description": "Παντελόνι με πιέτες, κλείσιμο με φερμουάρ και κουμπί, θηλιές στη μέση, με τσέπες, λευκο",
"image_link": "https://2ccdn.celestino.gr/small/SK7732.1825-7#1F.JPG",
"link": "https://www.celestino.gr/el-GR/panteloni-me-pietes-lefko/prd/SK7732.1825/7?affiliate=linkwise&utm_source=linkwise&utm_medium=lw&utm_campaign=lw",
"part_number": "SK7732.1825.1",
"price": "13,99",
"product_type": "Παντελόνια/Παντελόνια",
"sizes_in_stock_feed": "S",
"title": "Παντελόνι με πιέτες SK7732.1825+1",
"update_history": [
{
"id_feed": 169,
"feed_name": "from linkwise",
"date_upd": 1674689686,
"field_history": []
},
{
"id_feed": 170,
"feed_name": "scrape info",
"date_upd": 1674697681,
"field_history": [
{
"field_name": "all_sizes",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "sizes_in_stock",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "breadcrumbs",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "breadcrumbs_url",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "color",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
}
]
}
],
}
From this data I can get the data based on id .for example:
$get_product = DB::connection('mongodb')->collection( $collection )->where( 'id', $id )->first();
Now, Is there anyway I can delete single or multiple keys from the document based on id?
For example, I want to delete the aff_link and availability key.

How to sort based on an array inside of an array in PHP?

Let's consider the following JSON response. It is a list of station objects.
[
{
"id": 43,
"trucks": [
{
"id": 24,
"vehicleType": {
"id": 2,
"vehicleType": "VT",
"createdAt": 1622645476000,
"updatedAt": 1622645476000
},
"sensor": {
"id": 16,
"devId": "tutorial",
"readings": [
{
"id": 36296,
"interiorTemperature": 528.36,
"batteryTemperature": 528.36,
"batteryVoltage": 0,
"createdAt": 1623065279000,
"updatedAt": 1623065279000
}
],
"resolved": false,
"createdAt": 1622645598000,
"updatedAt": 1622650553000
},
"vehicleNumber": 123456,
"truckStatus": true,
"defaultBatteryVoltage": "12",
"batteryTempThreshold": 25,
"interiorTempThresholdMax": 30,
"interiorTempThresholdMin": 5,
"batteryVoltageThreshold": 11.5,
"createdAt": 1622645517000,
"updatedAt": 1622645663000
},
{
"id": 29,
"vehicleType": {
"id": 2,
"vehicleType": "VT",
"createdAt": 1622645476000,
"updatedAt": 1622645476000
},
"sensor": {
"id": 23,
"devId": "value",
"readings": [
{
"id": 36298,
"interiorTemperature": 10,
"batteryTemperature": 10,
"batteryVoltage": 10,
"createdAt": 1623074142000,
"updatedAt": 1623074142000
}
],
"resolved": false,
"createdAt": 1623074089000,
"updatedAt": 1623074089000
},
"vehicleNumber": 313215,
"truckStatus": true,
"defaultBatteryVoltage": "12",
"batteryTempThreshold": 50,
"interiorTempThresholdMax": 50,
"interiorTempThresholdMin": 50,
"batteryVoltageThreshold": 50,
"createdAt": 1623073365000,
"updatedAt": 1623073365000
}
],
"name": "value",
"city": "value",
"address": "value",
"zipCode": "value",
"createdAt": 1622645352000,
"updatedAt": 1622645352000
},
{
"id": 44,
"trucks": [
{
"id": 25,
"vehicleType": {
"id": 3,
"vehicleType": "AG",
"createdAt": 1622647436000,
"updatedAt": 1622647436000
},
"sensor": {
"id": 18,
"devId": "test",
"readings": [
null
],
"resolved": false,
"createdAt": 1622795394000,
"updatedAt": 1622795394000
},
"vehicleNumber": 123457,
"truckStatus": true,
"defaultBatteryVoltage": "24",
"batteryTempThreshold": 80,
"interiorTempThresholdMax": 50,
"interiorTempThresholdMin": -20,
"batteryVoltageThreshold": 11.5,
"createdAt": 1622645584000,
"updatedAt": 1623074846000
}
],
"name": "value",
"city": "value",
"address": "value",
"zipCode": "11112",
"createdAt": 1622645431000,
"updatedAt": 1622645431000
},
{
"id": 46,
"trucks": [
{
"id": 26,
"vehicleType": {
"id": 2,
"vehicleType": "VT",
"createdAt": 1622645476000,
"updatedAt": 1622645476000
},
"sensor": null,
"vehicleNumber": 979787,
"truckStatus": true,
"defaultBatteryVoltage": "12",
"batteryTempThreshold": 123,
"interiorTempThresholdMax": 123,
"interiorTempThresholdMin": 123,
"batteryVoltageThreshold": 123,
"createdAt": 1623064671000,
"updatedAt": 1623064671000
}
],
"name": "value",
"city": "value",
"address": "value",
"zipCode": "11111",
"createdAt": 1622918304000,
"updatedAt": 1622918304000
}
]
All stations have an id, a list of trucks, and some basic info (name, location etc). With PHP, I convert this to an array object. What I would like to achieve is to sort the array. Now I have managed to sort based on name or location. I used the following snipped:
usort($stations, function($a, $b) {
$retval = $a['name'] <=> $b['name'];
return $retval;
});
Now it's all nice but we would like to sort it based on the highest interior temperature read in a station. To make the station with the highest interior temperature be the 0th element in the list and the one with the lowest (or no reading at all) is the nth. I have tried playing around with usort but I had no results. Is it even possible to sort it like that?

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.

php multidimension array dynamically

This is the static multidimension array and i converted to json.
$mailmsg = array(
'type'=> 'line',
'data' => array(
'labels' => array("1","2","3","4","5"),
'datasets' => array(array("label"=>"A","fill"=>"false","yAxisID"=>"A","borderColor"=>"#bae755","data"=>array(100, 96, 84, 76, 69)),array("label"=>"B","fill"=>"false","yAxisID"=>"B","borderColor"=>"#55bae7","data"=>array(1, 1, 1, 1, 0)),array("label"=>"C","fill"=>"false","yAxisID"=>"C","borderColor"=>"#e755ba","data"=>array(5, 15, 10, 10, 0)))),
' '=>array("scales"=>array("yAxes"=>array(array("scaleLabel"=>array("display"=>"true","labelString"=>"Prn1"),"id"=>"A","type"=>"linear","position"=>"left"),array("scaleLabel"=>array("display"=>"true","labelString"=>"Prn2"),"id"=>"B","type"=>"linear","position"=>"left"),array("scaleLabel"=>array("display"=>"true","labelString"=>"Prn3"),"id"=>"C","type"=>"linear","position"=>"left")))
));
echo $json = json_encode((object)$mailmsg, JSON_NUMERIC_CHECK);
Result:
{
"type": "line",
"data": {
"labels": ["1","2","3","4","5"],
"datasets": [{
"label": "A",
"fill": "false",
"yAxisID": "A",
"borderColor": "#bae755",
"data": [100, 96, 84, 76, 69]
}, {
"label": "B",
"fill": "false",
"yAxisID": "B",
"borderColor": "#55bae7",
"data": [1, 1, 1, 1, 0]
}, {
"label": "C",
"fill": "false",
"yAxisID": "C",
"borderColor": "#e755ba",
"data": [5, 15, 10, 10, 0]
}]
},
"options": {
"scales": {
"yAxes": [{
"scaleLabel": {
"display": "true",
"labelString": "Prn1"
},
"id": "A",
"type": "linear",
"position": "left"
}, {
"scaleLabel": {
"display": "true",
"labelString": "Prn2"
},
"id": "B",
"type": "linear",
"position": "left"
}, {
"scaleLabel": {
"display": "true",
"labelString": "Prn3"
},
"id": "C",
"type": "linear",
"position": "left"
}]
}
}
}
I need to above static array to change dynamically using foreach.
just pass the reference to the specific data in the array:
foreach($mailmsg['data']['datasets'] as $key => $value){
}

How to JSON with duplicate 'id' values?

I am receiving data from another site with json API.
how can I get the data of the objects with the same id number.
I try as follows but it turns blank..
there are 10 objects with the same id number
how can i get them.
The typeid number is the same but the specialvalue value is different.
{"id":4620041,"active":true,"typeid":56,"specialvalue":"0.5","fields":{"magic":{"active":true,"type":"magic","value":"1.05"},"xmagic":{"active":true,"type":"xmagic","value":"7.5"}}}
{"id":4620045,"active":true,"typeid":56,"specialvalue":"1.5","fields":{"magic":{"active":true,"type":"magic","value":"3.05"},"xmagic":{"active":true,"type":"xmagic","value":"3.5"}}}
if($test->typeid =="56")
{
if (specialvalue == "0.5") {
$alta = $test->fields->magic->value;
$uste = $test->fields->xmagic->value;
}
}
echo $alta - $uste ;
Thank you in advance for your help
https://i.hizliresim.com/Pl0LL7.jpg
Few observations :
Provided JSON is not a valid JSON.
It should be an array of objects to filter the specific data as per the requirement.
Solution :
let jsonObj = [{
"id": 5246752,
"active": true,
"typeid": 56,
"specialvalue": "0.5",
"fields": {
"magic": {
"active": true,
"type": "magic",
"value": "1.06"
},
"xmagic": {
"active": true,
"type": "xmagic",
"value": "7.0"
}
}
}, {
"id": 5246753,
"active": true,
"typeid": 56,
"specialvalue": "1.5",
"fields": {
"magic": {
"active": true,
"type": "magic",
"value": "1.35"
},
"xmagic": {
"active": true,
"type": "xmagic",
"value": "3.0"
}
}
}, {
"id": 5246754,
"active": true,
"typeid": 56,
"specialvalue": "2.5",
"fields": {
"magic": {
"active": true,
"type": "magic",
"value": "2.0"
},
"xmagic": {
"active": true,
"type": "xmagic",
"value": "1.7"
}
}
}, {
"id": 5246755,
"active": true,
"typeid": 56,
"specialvalue": "3.5",
"fields": {
"magic": {
"active": true,
"type": "magic",
"value": "3.45"
},
"xmagic": {
"active": true,
"type": "xmagic",
"value": "1.25"
}
}
}, {
"id": 5246756,
"active": true,
"typeid": 56,
"specialvalue": "4.5",
"fields": {
"magic": {
"active": true,
"type": "magic",
"value": "6.25"
},
"xmagic": {
"active": true,
"type": "xmagic",
"value": "1.08"
}
}
}, {
"id": 5246757,
"active": true,
"typeid": 56,
"specialvalue": "5.5",
"fields": {
"magic": {
"active": true,
"type": "magic",
"value": "9.5"
},
"xmagic": {
"active": true,
"type": "xmagic",
"value": "1.02"
}
}
}];
let filteredData = jsonObj.filter(item => item.typeid===56 && item.specialvalue==="0.5");
console.log(filteredData);
Use .filter
var filteredData = data.filter(
(el) => {
return el.typeid===56 && el.specialvalue==="0.5";
}
);
This will return only those elements with el.typeid===56 && specialvalue==="0.5"

Categories