How to access JSON object values using vue steps? - php

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.

Related

Compare 2 Multidimensional Arrays in PHP and show all the difference in an array

I have 2 Multiple-Arrays and I want to compare them. In the second Array I want then show with colors which value has changed, which key is new and which key is removed.
I have found a lot of different solutions, but no one function for me.
Here are my arrays:
{
"originFormation": {
"stationName": "Bern",
"sections": [{
"name": "B",
"cars": [{
"type": "LOK",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": false,
"nextPassage": false
}]
}, {
"name": "C",
"cars": [{
"type": "CAR",
"number": "1",
"class": "1",
"occupancy": "UNKNOWN",
"attributes": ["AbteilRollstuhl", "AbteilBusiness"],
"closed": false,
"previousPassage": false,
"nextPassage": true
}, {
"type": "CAR",
"number": "1",
"class": "2",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": true,
"nextPassage": true
}]
}],
"legendItems": [{
"id": "1",
"text": "1st class coach",
"refersTo": "type"
}, {
"id": "2",
"text": "2st class coach",
"refersTo": "type"
}, {
"id": "Fahrtrichtung",
"text": "Direction of travel",
"refersTo": "code"
}, {
"id": "FA",
"text": "Family Coach with play area",
"refersTo": "type"
}, {
"id": "AbteilRollstuhl",
"text": "Wheelchair space",
"refersTo": "code"
}, {
"id": "AbteilVeloPl",
"text": "Bicycle loading: Without reservation",
"refersTo": "code"
}, {
"id": "LK",
"text": "Locomotive",
"refersTo": "type"
}, {
"id": "WR",
"text": "Restaurant 1st and 2nd class",
"refersTo": "type"
}, {
"id": "AbteilBusiness",
"text": "Business zone in 1st class: Reservation possible",
"refersTo": "code"
},
{
"id": "HFS_WG_NUM",
"text": "Coach",
"refersTo": "code"
}, {
"id": "KD",
"text": "No passage",
"refersTo": "type"
}
],
"info": {
"title": "Changes to the composition of the train",
"formationChanges": []
}
}
}
Array2:
{
"originFormation": {
"stationName": "Bern",
"sections": [
{
"name": "B",
"cars": [
{
"type": "LOK",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": false,
"nextPassage": false
}
]
},
{
"name": "C",
"cars": [
{
"type": "CAR",
"number": "12",
"class": "1",
"occupancy": "UNKNOWN",
"attributes": [
"AbteilRollstuhl",
"AbteilBusiness"
],
"closed": false,
"previousPassage": false,
"nextPassage": true
},
{
"type": "CAR",
"number": "1",
"class": "2",
"occupancy": "UNKNOWN",
"attributes": [
"AbteilStefan"
],
"closed": false,
"previousPassage": true,
"nextPassage": true
},
{
"type": "CAR",
"number": "2",
"class": "1",
"occupancy": "UNKNOWN",
"attributes": [],
"closed": false,
"previousPassage": true,
"nextPassage": true
}
]
}
],
"legendItems": [
{
"id": "1",
"text": "1st class coach",
"refersTo": "type"
},
{
"id": "2",
"text": "2st class coach",
"refersTo": "type"
},
{
"id": "Fahrtrichtung",
"text": "Direction of travel",
"refersTo": "code"
},
{
"id": "FA",
"text": "Family Coach with play area",
"refersTo": "type"
},
{
"id": "AbteilRollstuhl",
"text": "Wheelchair space",
"refersTo": "code"
},
{
"id": "AbteilVeloPl",
"text": "Bicycle loading: Without reservation",
"refersTo": "code"
},
{
"id": "LK",
"text": "Locomotive",
"refersTo": "type"
},
{
"id": "WR",
"text": "Restaurant 1st and 2nd class",
"refersTo": "type"
},
{
"id": "AbteilBusiness",
"text": "Business zone in 1st class: Reservation possible",
"refersTo": "code"
},
{
"id": "AbteilStefan",
"text": "Ich bin ein neues Abteil",
"refersTo": "code"
},
{
"id": "HFS_WG_NUM",
"text": "Coach",
"refersTo": "code"
},
{
"id": "KD",
"text": "No passage",
"refersTo": "type"
}
],
"info": {
"title": "Changes to the composition of the train",
"formationChanges": [
"All Changed"
]
}
}
}
My fonction to compare:
function array_diff_assoc_recursive($array1, $array2)
{
foreach($array1 as $key => $value)
{
if(is_array($value))
{
if(!isset($array2[$key]))
{
$difference[$key] = $value;
}
elseif(!is_array($array2[$key]))
{
$difference[$key] = "<b>".$value."</b>";
}
else
{
$new_diff = array_diff_assoc_recursive($value, $array2[$key]);
if($new_diff != FALSE)
{
$difference[$key] = $new_diff;
}
}
}
elseif(!isset($array2[$key]) || $array2[$key] != $value)
{
$difference[$key] = "<b>".$value."</b>";
}
}
return !isset($difference) ? 0 : $difference;
}
var_dump(array_diff_assoc_recursive($array2, $array1));
This difference i get:
[originformation][sections][1][cars][0][number] -> newValue 12
[originformation][sections][1][cars][1][attributes] -> newValue AbteilStefan
[originformation][sections][1][cars][2] -> all Attributes are new
[originformation][legendItems][9][id] -> newValue AbteilStefan
[originformation][legendItems][9][text] -> newValue Ich bin ein neues Abteil
[originformation][legendItems][10] -> all Attributes are new
[originformation][legendItems][11] -> all Attributes are new
[originformation][info][formationChanges][0] => newValue All Changed
The difference i expected
[originformation][sections][1][cars][0][number] -> newValue 12
[originformation][sections][1][cars][1] -> all Attributes are new
[originformation][legendItems][9] -> all Attributes are new
[originformation][info][formationChanges][0] => newValue All Changed
Problem
My function doesn't see, that car in Array2 I put in a complete new car and also a complete new legendItem and the rest is still the same.
Does someone know how I can compare the arrays, that he doesn't check the order of the attributes on the same level?

Set PHP variable to value in JSON object

I have a PHP file which gets a JSON object called $response. The $response has many values (as shown below) and I want to extract a few includes title and price. I have tried the below code but it doesnt show ANY result (no error, no value!). Thoughts?
Thank you
PHP code:
$data = json_decode($response, true);
echo $data->ItemsResult->Items[0]->ItemInfo->Title->DisplayValue;
$response =
{
"ItemsResult": {
"Items": [{
"ASIN": "B0825SNHP1",
"BrowseNodeInfo": {
"BrowseNodes": [{
"Ancestor": {
"Ancestor": {
"Ancestor": {
"ContextFreeName": "Toys & Games",
"DisplayName": "Toys & Games",
"Id": "165793011"
},
"ContextFreeName": "Toys & Games",
"DisplayName": "Categories",
"Id": "165795011"
},
"ContextFreeName": "Stuffed Animals & Plush Toys",
"DisplayName": "Stuffed Animals & Plush Toys",
"Id": "166461011"
},
"ContextFreeName": "Plush Figure Toys",
"DisplayName": "Plush Figures",
"Id": "11350121011",
"IsRoot": false,
"SalesRank": 1
}],
"WebsiteSalesRank": {
"ContextFreeName": "Toys & Games",
"DisplayName": "Toys & Games",
"SalesRank": 32
}
},
"DetailPageURL": "https://www.amazon.com/dp/B0825SNHP1?tag=tpf0bee-20&linkCode=ogi&th=1&psc=1",
"Images": {
"Primary": {
"Large": {
"Height": 500,
"URL": "https://m.media-amazon.com/images/I/51P8jTxbP2L.jpg",
"Width": 467
},
"Medium": {
"Height": 160,
"URL": "https://m.media-amazon.com/images/I/51P8jTxbP2L._SL160_.jpg",
"Width": 149
},
"Small": {
"Height": 75,
"URL": "https://m.media-amazon.com/images/I/51P8jTxbP2L._SL75_.jpg",
"Width": 70
}
},
"Variants": [{
"Large": {
"Height": 450,
"URL": "https://m.media-amazon.com/images/I/51myKYEuuuL.jpg",
"Width": 500
},
"Medium": {
"Height": 144,
"URL": "https://m.media-amazon.com/images/I/51myKYEuuuL._SL160_.jpg",
"Width": 160
},
"Small": {
"Height": 68,
"URL": "https://m.media-amazon.com/images/I/51myKYEuuuL._SL75_.jpg",
"Width": 75
}
}, {
"Large": {
"Height": 500,
"URL": "https://m.media-amazon.com/images/I/515j0HmJV0L.jpg",
"Width": 500
},
"Medium": {
"Height": 160,
"URL": "https://m.media-amazon.com/images/I/515j0HmJV0L._SL160_.jpg",
"Width": 160
},
"Small": {
"Height": 75,
"URL": "https://m.media-amazon.com/images/I/515j0HmJV0L._SL75_.jpg",
"Width": 75
}
}, {
"Large": {
"Height": 466,
"URL": "https://m.media-amazon.com/images/I/51ARoLKEn5L.jpg",
"Width": 500
},
"Medium": {
"Height": 149,
"URL": "https://m.media-amazon.com/images/I/51ARoLKEn5L._SL160_.jpg",
"Width": 160
},
"Small": {
"Height": 70,
"URL": "https://m.media-amazon.com/images/I/51ARoLKEn5L._SL75_.jpg",
"Width": 75
}
}, {
"Large": {
"Height": 500,
"URL": "https://m.media-amazon.com/images/I/414gFkO4AmL.jpg",
"Width": 446
},
"Medium": {
"Height": 160,
"URL": "https://m.media-amazon.com/images/I/414gFkO4AmL._SL160_.jpg",
"Width": 143
},
"Small": {
"Height": 75,
"URL": "https://m.media-amazon.com/images/I/414gFkO4AmL._SL75_.jpg",
"Width": 67
}
}, {
"Large": {
"Height": 500,
"URL": "https://m.media-amazon.com/images/I/516zb5W2o3L.jpg",
"Width": 476
},
"Medium": {
"Height": 160,
"URL": "https://m.media-amazon.com/images/I/516zb5W2o3L._SL160_.jpg",
"Width": 152
},
"Small": {
"Height": 75,
"URL": "https://m.media-amazon.com/images/I/516zb5W2o3L._SL75_.jpg",
"Width": 71
}
}]
},
"ItemInfo": {
"ByLineInfo": {
"Brand": {
"DisplayValue": "Mattel",
"Label": "Brand",
"Locale": "en_US"
},
"Manufacturer": {
"DisplayValue": "Mattel",
"Label": "Manufacturer",
"Locale": "en_US"
}
},
"Classifications": {
"Binding": {
"DisplayValue": "Accessory",
"Label": "Binding",
"Locale": "en_US"
},
"ProductGroup": {
"DisplayValue": "Toy",
"Label": "ProductGroup",
"Locale": "en_US"
}
},
"ContentInfo": {
"Edition": {
"DisplayValue": "Star Wars Edition",
"Label": "Edition",
"Locale": "en_US"
}
},
"ExternalIds": {
"EANs": {
"DisplayValues": ["0887961938814"],
"Label": "EAN",
"Locale": "en_US"
},
"UPCs": {
"DisplayValues": ["887961938814"],
"Label": "UPC",
"Locale": "en_US"
}
},
"Features": {
"DisplayValues": ["This 11-inch The Child plush toy will capture the hearts of Star Wars fans everywhere", "Inspired by the Disney+ series The Mandalorian, the adorable figure with green skin, big ears and large eyes resembles a baby Yoda but is referred to as The Child.", "The toy plush has a soft body, plus a sturdy base filled with beans, perfect for cuddling or display as a collectible", "The character wears his robes as seen in the show.", "Star Wars fans will love taking on the role of The Mandalorian Bounty Hunter and caring for The Child on their own", "Material Type: Polyester"],
"Label": "Features",
"Locale": "en_US"
},
"ManufactureInfo": {
"ItemPartNumber": {
"DisplayValue": "GWD85",
"Label": "PartNumber",
"Locale": "en_US"
},
"Model": {
"DisplayValue": "GWD85",
"Label": "Model",
"Locale": "en_US"
},
"Warranty": {
"DisplayValue": "No Warranty",
"Label": "Warranty",
"Locale": "en_US"
}
},
"ProductInfo": {
"Color": {
"DisplayValue": "Green",
"Label": "Color",
"Locale": "en_US"
},
"IsAdultProduct": {
"DisplayValue": false,
"Label": "IsAdultProduct",
"Locale": "en_US"
},
"ItemDimensions": {
"Height": {
"DisplayValue": 11.02,
"Label": "Height",
"Locale": "en_US",
"Unit": "Inches"
},
"Length": {
"DisplayValue": 5.98,
"Label": "Length",
"Locale": "en_US",
"Unit": "Inches"
},
"Weight": {
"DisplayValue": 0.220462262,
"Label": "Weight",
"Locale": "en_US",
"Unit": "Pounds"
},
"Width": {
"DisplayValue": 7.99,
"Label": "Width",
"Locale": "en_US",
"Unit": "Inches"
}
},
"ReleaseDate": {
"DisplayValue": "2020-02-12T00:00:01Z",
"Label": "ReleaseDate",
"Locale": "en_US"
},
"Size": {
"DisplayValue": "11 inches",
"Label": "Size",
"Locale": "en_US"
},
"UnitCount": {
"DisplayValue": 1,
"Label": "NumberOfItems",
"Locale": "en_US"
}
},
"Title": {
"DisplayValue": "Mattel Star Wars The Child Plush Toy, 11-Inch Small Yoda-Like Soft Figure from The Mandalorian, Green",
"Label": "Title",
"Locale": "en_US"
}
},
"Offers": {
"Listings": [{
"Availability": {
"Message": "In stock. Usually ships within 4 to 5 days.",
"MinOrderQuantity": 1,
"Type": "Now"
},
"Condition": {
"SubCondition": {
"Value": "New"
},
"Value": "New"
},
"DeliveryInfo": {
"IsAmazonFulfilled": false,
"IsFreeShippingEligible": false,
"IsPrimeEligible": false
},
"Id": "xZd%2BKU9rGH7fWwKPEUHMfhsQHzl3QpAN6kIllBjmOl90egwIXEDSkqIt1nqy2q90nMMKYhKCECzkZugn%2FhS6MNMQ0DeGGHgqoDimWML40ChnAKQi3WGnvzASkBlZn3fOYl%2Fk7qoY%2FkafbujzE4UkOjHO6D2nEkcs",
"IsBuyBoxWinner": false,
"MerchantInfo": {
"DefaultShippingCountry": "US",
"FeedbackCount": 261,
"FeedbackRating": 3.53,
"Id": "A111I7FGCUO8HR",
"Name": "ZDeals"
},
"Price": {
"Amount": 27.58,
"Currency": "USD",
"DisplayAmount": "$27.58"
},
"ProgramEligibility": {
"IsPrimeExclusive": false,
"IsPrimePantry": false
},
"ViolatesMAP": false
}],
"Summaries": [{
"Condition": {
"Value": "Collectible"
},
"HighestPrice": {
"Amount": 68.94,
"Currency": "USD",
"DisplayAmount": "$68.94"
},
"LowestPrice": {
"Amount": 58.99,
"Currency": "USD",
"DisplayAmount": "$58.99"
},
"OfferCount": 2
}, {
"Condition": {
"Value": "New"
},
"HighestPrice": {
"Amount": 58.75,
"Currency": "USD",
"DisplayAmount": "$58.75"
},
"LowestPrice": {
"Amount": 22.48,
"Currency": "USD",
"DisplayAmount": "$22.48"
},
"OfferCount": 224
}]
}
}]
}
}
The second argument of json_decode function enables associative array result. So in your case you can either do
$data = json_decode($response);
echo $data->ItemsResult->Items[0]->ItemInfo->Title->DisplayValue;
or
$data = json_decode($response, true);
echo $data['ItemsResult']['Items'][0]['ItemInfo']['Title']['DisplayValue'];

A Non Numeric Value Encountered When Trying To Return Data URL PHP

I am currently trying to present a screen shot of a webpage after a user inputs a custom url. I am using google api pagespeedonline to grab the contents of the page as well as fetch the actual data url but when i go to return it on my backend I cant get it to successfuly return just the data url. My current code for doing so is:
public function web_preview(Request $request)
{
try {
$url = $this->check_url($request->input('url'));
} catch (\Exception $e) {
return $this->badRequestResponse($e->getMessage());
}
$info = $this->curl_file_info($url, $this::$ACCEPTABLE_HTML);
if (!$this->is_textual($info))
return $this->clientErrorResponse("Nontextual web asset");
if ($info["http_code"] !== 200)
return $this->clientErrorResponse("URL returned ",$info["http_code"]);
try {
$curl_init = curl_init(
"https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=" + $url + "&key=AIzaSyCxGGWVSSY3fau3cPekSaY765XKRKHerNY&screenshot=true");
curl_setopt($curl_init, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl_init);
curl_close($curl_init);
//call Google PageSpeed Insights API
//decode json data
$googlepsdata = json_decode($response);
//screenshot data
$snap = $googlepsdata['screenshot-thumbnails']['details']['data'];
} catch(\Exception $e) {
return $this->internalServerError($e->getMessage());
}
// $img = Image::make($snap);
return $snap;
}
and the curl_init should return this:
{
"captchaResult": "CAPTCHA_NOT_NEEDED",
"kind": "pagespeedonline#result",
"id": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs",
"loadingExperience": {
"id": "https://developer.mozilla.org",
"metrics": {
"CUMULATIVE_LAYOUT_SHIFT_SCORE": {
"percentile": 0,
"distributions": [
{
"min": 0,
"max": 10,
"proportion": 0.97998381341452667
},
{
"min": 10,
"max": 25,
"proportion": 0.01036026216807024
},
{
"min": 25,
"proportion": 0.00965592441740298
}
],
"category": "FAST"
},
"LARGEST_CONTENTFUL_PAINT_MS": {
"percentile": 1415,
"distributions": [
{
"min": 0,
"max": 2500,
"proportion": 0.92849265950201776
},
{
"min": 2500,
"max": 4000,
"proportion": 0.046497587955101477
},
{
"min": 4000,
"proportion": 0.025009752542881025
}
],
"category": "FAST"
},
"FIRST_INPUT_DELAY_MS": {
"percentile": 3,
"distributions": [
{
"min": 0,
"max": 100,
"proportion": 0.99082487343845982
},
{
"min": 100,
"max": 300,
"proportion": 0.005724879537811014
},
{
"min": 300,
"proportion": 0.0034502470237293141
}
],
"category": "FAST"
},
"FIRST_CONTENTFUL_PAINT_MS": {
"percentile": 1386,
"distributions": [
{
"min": 0,
"max": 1000,
"proportion": 0.55192771567034826
},
{
"min": 1000,
"max": 3000,
"proportion": 0.4031506848279558
},
{
"min": 3000,
"proportion": 0.044921599501695914
}
],
"category": "AVERAGE"
}
},
"overall_category": "AVERAGE",
"initial_url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs",
"origin_fallback": true
},
"originLoadingExperience": {
"id": "https://developer.mozilla.org",
"metrics": {
"CUMULATIVE_LAYOUT_SHIFT_SCORE": {
"percentile": 0,
"distributions": [
{
"min": 0,
"max": 10,
"proportion": 0.97998381341452667
},
{
"min": 10,
"max": 25,
"proportion": 0.01036026216807024
},
{
"min": 25,
"proportion": 0.00965592441740298
}
],
"category": "FAST"
},
"LARGEST_CONTENTFUL_PAINT_MS": {
"percentile": 1415,
"distributions": [
{
"min": 0,
"max": 2500,
"proportion": 0.92849265950201776
},
{
"min": 2500,
"max": 4000,
"proportion": 0.046497587955101477
},
{
"min": 4000,
"proportion": 0.025009752542881025
}
],
"category": "FAST"
},
"FIRST_INPUT_DELAY_MS": {
"percentile": 3,
"distributions": [
{
"min": 0,
"max": 100,
"proportion": 0.99082487343845982
},
{
"min": 100,
"max": 300,
"proportion": 0.005724879537811014
},
{
"min": 300,
"proportion": 0.0034502470237293141
}
],
"category": "FAST"
},
"FIRST_CONTENTFUL_PAINT_MS": {
"percentile": 1386,
"distributions": [
{
"min": 0,
"max": 1000,
"proportion": 0.55192771567034826
},
{
"min": 1000,
"max": 3000,
"proportion": 0.4031506848279558
},
{
"min": 3000,
"proportion": 0.044921599501695914
}
],
"category": "AVERAGE"
}
},
"overall_category": "AVERAGE",
"initial_url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
},
"lighthouseResult": {
"requestedUrl": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs",
"finalUrl": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs",
"lighthouseVersion": "6.1.0",
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/83.0.4103.93 Safari/537.36",
"fetchTime": "2020-08-03T16:07:01.225Z",
"environment": {
"networkUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4143.7 Safari/537.36 Chrome-Lighthouse",
"hostUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/83.0.4103.93 Safari/537.36",
"benchmarkIndex": 674
},
"runWarnings": [],
"configSettings": {
"emulatedFormFactor": "desktop",
"locale": "en-US",
"onlyCategories": [
"performance"
],
"channel": "lr"
},
"audits": {
"critical-request-chains": {
"id": "critical-request-chains",
"title": "Avoid chaining critical requests",
"description": "The Critical Request Chains below show you what resources are loaded with a high priority. Consider reducing the length of chains, reducing the download size of resources, or deferring the download of unnecessary resources to improve page load. [Learn more](https://web.dev/critical-request-chains/).",
"score": null,
"scoreDisplayMode": "informative",
"displayValue": "8 chains found",
"details": {
"type": "criticalrequestchain",
"chains": {
"A5325AC8B1B236F134BF51AA757298E3": {
"children": {
"26.14": {
"request": {
"url": "https://developer.mozilla.org/static/build/styles/l10n-survey.0eeb824ed1eb.css",
"responseReceivedTime": 463937.629765,
"startTime": 463937.613606,
"transferSize": 1436,
"endTime": 463937.629767
}
},
"26.5": {
"request": {
"transferSize": 1570,
"endTime": 463937.662484,
"url": "https://developer.mozilla.org/static/build/styles/auth-modal.be43f0f58a73.css",
"responseReceivedTime": 463937.662481,
"startTime": 463937.611824
}
},
"26.4": {
"request": {
"endTime": 463937.630225,
"startTime": 463937.611595,
"transferSize": 2284,
"responseReceivedTime": 463937.630223,
"url": "https://developer.mozilla.org/static/build/styles/react-header.78d662924939.css"
}
},
"26.12": {
"request": {
"endTime": 463937.634264,
"url": "https://developer.mozilla.org/static/build/styles/banners.e6cd46767c2e.css",
"responseReceivedTime": 463937.63426200004,
"startTime": 463937.613176,
"transferSize": 1376
}
},
"26.8": {
"request": {
"transferSize": 1829,
"startTime": 463937.612959,
"endTime": 463937.662893,
"responseReceivedTime": 463937.662891,
"url": "https://developer.mozilla.org/static/build/styles/prism.a6f275e5032b.css"
}
},
"26.6": {
"request": {
"endTime": 463937.650866,
"url": "https://developer.mozilla.org/static/build/styles/react-mdn.4e0ead71927e.css",
"responseReceivedTime": 463937.65086299996,
"startTime": 463937.612255,
"transferSize": 35533
}
},
"26.13": {
"request": {
"startTime": 463937.613339,
"endTime": 463937.629323,
"transferSize": 1508,
"url": "https://developer.mozilla.org/static/build/styles/mdn-subscriptions.dbb82432d74c.css",
"responseReceivedTime": 463937.62931999995
}
},
"26.7": {
"request": {
"transferSize": 1557,
"startTime": 463937.61266,
"responseReceivedTime": 463937.63605599996,
"endTime": 463937.636059,
"url": "https://developer.mozilla.org/static/build/styles/subscriptions.3cebf84de805.css"
}
}
},
"request": {
"url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs",
"transferSize": 61560,
"responseReceivedTime": 463937.594315,
"endTime": 463937.594317,
"startTime": 463937.53046
}
}
},
"longestChain": {
"transferSize": 1829,
"duration": 132.43300002068281,
"length": 2
}
}
},
"estimated-input-latency": {
"id": "estimated-input-latency",
"title": "Estimated Input Latency",
"description": "Estimated Input Latency is an estimate of how long your app takes to respond to user input, in milliseconds, during the busiest 5s window of page load. If your latency is higher than 50 ms, users may perceive your app as laggy. [Learn more](https://web.dev/estimated-input-latency/).",
"score": 1,
"scoreDisplayMode": "numeric",
"displayValue": "10 ms",
"numericValue": 12.8
},
"total-byte-weight": {
"id": "total-byte-weight",
"title": "Avoids enormous network payloads",
"description": "Large network payloads cost users real money and are highly correlated with long load times. [Learn more](https://web.dev/total-byte-weight/).",
"score": 1,
"scoreDisplayMode": "numeric",
"displayValue": "Total size was 330 KiB",
"details": {
"type": "table",
"headings": [
{
"itemType": "url",
"text": "URL",
"key": "url"
},
{
"text": "Transfer Size",
"itemType": "bytes",
"key": "totalBytes"
}
],
"items": [
{
"url": "https://developer.mozilla.org/static/build/js/react-main.739f5d7ca4fd.js",
"totalBytes": 93235
},
{
"totalBytes": 61560,
"url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
},
{
"url": "https://developer.mozilla.org/static/build/styles/react-mdn.4e0ead71927e.css",
"totalBytes": 35533
},
{
"url": "https://developer.mozilla.org/static/fonts/locales/ZillaSlab-Bold.subset.e96c15f68c68.woff2",
"totalBytes": 34693
},
{
"url": "https://developer.mozilla.org/static/fonts/locales/ZillaSlab-Regular.subset.bbc33fb47cf6.woff2",
"totalBytes": 34437
},
{
"totalBytes": 19085,
"url": "https://www.google-analytics.com/analytics.js"
},
{
"url": "https://developer.mozilla.org/static/build/js/react-bcd-signal.cf0fc711cfa2.js",
"totalBytes": 8283
},
{
"url": "https://cdn.speedcurve.com/js/lux.js?id=108906238",
"totalBytes": 7537
},
{
"url": "https://developer.mozilla.org/static/img/web-docs-sprite.22a6a085cf14.svg",
"totalBytes": 4019
},
{
"url": "https://developer.mozilla.org/static/build/styles/react-header.78d662924939.css",
"totalBytes": 2284
}
]
},
"numericValue": 337833
},
"speed-index": {
"id": "speed-index",
"title": "Speed Index",
"description": "Speed Index shows how quickly the contents of a page are visibly populated. [Learn more](https://web.dev/speed-index/).",
"score": 0.99,
"scoreDisplayMode": "numeric",
"displayValue": "0.8 s",
"numericValue": 775.287095961904
},
"mainthread-work-breakdown": {
"id": "mainthread-work-breakdown",
"title": "Minimizes main-thread work",
"description": "Consider reducing the time spent parsing, compiling and executing JS. You may find delivering smaller JS payloads helps with this. [Learn more](https://web.dev/mainthread-work-breakdown/)",
"score": 1,
"scoreDisplayMode": "numeric",
"displayValue": "0.5 s",
"details": {
"type": "table",
"headings": [
{
"itemType": "text",
"text": "Category",
"key": "groupLabel"
},
{
"itemType": "ms",
"key": "duration",
"text": "Time Spent",
"granularity": 1
}
],
"items": [
{
"duration": 171.94199999999989,
"group": "scriptEvaluation",
"groupLabel": "Script Evaluation"
},
{
"group": "styleLayout",
"groupLabel": "Style & Layout",
"duration": 118.24500000000002
},
{
"group": "other",
"groupLabel": "Other",
"duration": 89.691999999999837
},
{
"groupLabel": "Rendering",
"duration": 32.649999999999984,
"group": "paintCompositeRender"
},
{
"groupLabel": "Parse HTML & CSS",
"duration": 28.025000000000002,
"group": "parseHTML"
},
{
"duration": 16.613,
"group": "scriptParseCompile",
"groupLabel": "Script Parsing & Compilation"
},
{
"group": "garbageCollection",
"groupLabel": "Garbage Collection",
"duration": 2.731
}
]
},
"numericValue": 459.89799999999968
},
"screenshot-thumbnails": {
"id": "screenshot-thumbnails",
"title": "Screenshot Thumbnails",
"description": "This is what the load of your site looked like.",
"score": null,
"scoreDisplayMode": "informative",
"details": {
"type": "filmstrip",
"items": [
{
"timing": 300,
"timestamp": 463937829358,
"data": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRQBAwQEBQQFCQUFCRQNCw0UFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFP/AABEIAFMAeAMBEQACEQEDEQH/xAGiAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+gEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoLEQACAQ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JTGWIZ0j+zkvgFCMHDZb5gFyR26AnJ7ottrnnjNnpltIr7zCbia4hJATKFwYDsy3ynPTtuPy0ihuiahqusxai66FpqfZ5PKh/0+4AlOA2SXtlwMMOU3jOR1BAAN5LGctKH0+1VQp8srdOdxy2A3yDaMbeRnqfQEgFSC31RrvbPo2nx2uOJI9Rkd87SeVMIH3go+93J7YIBsf2Za/88R+ZoAP7Mtf+eQ/M0AH9mWv/ADyH5mgB0dhbxOHSMKw6HJoAqX13Itz5EMpilfG1ntZJIx65YEL06DI59c4qla2xnJ2e/wCBFpQv5ji4vLSdIyUkSKzeI9MgfNI2OCO3Ptmh2FFX6/ga9SajLiVYIJJGICopYkkAAAep6UAcsPFF5cJNcpGI7WCTaYj5DyTDYDtV1uNqtktywAwp46EgGWfGWrNaahOkluEiViJPLtisWLZ5ct/pvOf3bclflPOFbeoAyy8Z63JdRwL9nu2dodzQxW/y7o0ZuPtxPzbyygDhVP3+GYAty654gS0haOW2uJJVDuY7WIi3Hl7SrZvACVkwSVJGDtGfvAATUvGt1Za8mkxXNrPfyJO0emp9n+1sqoxik2tdKSpaOReF5IOfLCswAGN4q13yVlSBPneVZYnhtw1oCVEZkP23Hy87tuS29cbMEF2FdXsai6rrVzbbbYRTtOw8m+ht0aCJSCAzr9o3OM7WyvVWAwDkhBe50NhHcxWkSXk0dxcgYeWGIxqx9QpZiPzNAyxQAUAFAHEeO/EGoaRn7JcGH97bL91W4d2DdQeoAreEVLc451Jp2TKHw78UapresXMF7dGeKNHKqUUYxIQOQBngCipCMVoXSnKTsz0asDpCgBqxoo4UDtwKADYoz8o568daAEMSEg7FyDkHHegBwAHQYoAjuLWG7t5IJ4Y5oJFKvFIoZWB6gg8EHJoAkCgEnAyepxQKy3ECKpJAAJ9BQCSWw6gYUAFABQB//9k="
},
with the screenshot/data url being at the very bottom, it appears that the try catch may be hitting the catch but i cant tell why, does anyone have any ideas?

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"

How to create a combo chart (bar and line) with fusioncharts using data from MySQL database?

I found this code online to do basically everything I was looking for except they are not using data from a MySQL database where as I am. Here is their code:
{
"chart": {
"caption": "Inventory by Product Categories",
"bgcolor": "FFFFFF",
"plotgradientcolor": "",
"showalternatehgridcolor": "0",
"showplotborder": "0",
"divlinecolor": "CCCCCC",
"showvalues": "0",
"showcanvasborder": "0",
"pyaxisname": "Cost of Inventory",
"syaxisname": "Units in Inventory",
"numberprefix": "$",
"labeldisplay": "STAGGER",
"slantlabels": "1",
"canvasborderalpha": "0",
"legendshadow": "0",
"legendborderalpha": "0",
"showborder": "0"
},
"categories": [
{
"category": [
{
"label": "Seafood",
"labelPadding": 0
},
{
"label": "Beverages",
"labelPadding": 12
},
{
"label": "Condiments",
"labelPadding": 0
},
{
"label": "Dairy Products",
"labelPadding": 12
},
{
"label": "Confections",
"labelPadding": 0
},
{
"label": "Meat/Poultry",
"labelPadding": 12
},
{
"label": "Grains/Cereals",
"labelPadding": 0
},
{
"label": "Produce",
"labelPadding": 12
}
]
}
],
"dataset": [
{
"seriesname": "Cost of Inventory",
"color": "008ee4",
"data": [
{
"value": "13510"
},
{
"value": "12480"
},
{
"value": "12024"
},
{
"value": "11271"
},
{
"value": "10392"
},
{
"value": "5729"
},
{
"value": "5594"
},
{
"value": "3549"
}
]
},
{
"seriesname": "Quantity",
"parentyaxis": "S",
"renderas": "Line",
"color": "f8bd19",
"data": [
{
"value": "701"
},
{
"value": "559"
},
{
"value": "507"
},
{
"value": "393"
},
{
"value": "386"
},
{
"value": "165"
},
{
"value": "258"
},
{
"value": "100"
}
]
}
]
}
This makes sense, but it's changing this JSON code to accept data from a database instead of hardcoding this that is difficult for me.
Here is the relevent part of my code:
<?php
$strQuery2 = "SELECT ScrapDate, SUM(Quantity) AS Quantity FROM Scrap WHERE Department = 'WE' GROUP BY ScrapDate ORDER BY ScrapDate";
// Execute the query, or else return the error message.
$result2 = $dbhandle->query($strQuery2) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");
// If the query returns a valid response, prepare the JSON string
if ($result2) {
// The `$arrData` array holds the chart attributes and data
$arrData2 = array(
"chart" => array(
"caption" => "WE Last Week Scrap Quantity",
"paletteColors" => "#0075c2",
"bgColor" => "#ffffff",
"borderAlpha"=> "20",
"canvasBorderAlpha"=> "0",
"usePlotGradientColor"=> "0",
"plotBorderAlpha"=> "10",
"showXAxisLine"=> "1",
"xAxisLineColor" => "#999999",
"showValues"=> "0",
"divlineColor" => "#999999",
"divLineIsDashed" => "1",
"showAlternateHGridColor" => "0",
"xAxisName"=> "Day",
"yAxisName"=> "Quantity"
)
);
$arrData2["data"] = array();
// Push the data into the array
while($row2 = mysqli_fetch_array($result2)) {
array_push($arrData2["data"], array(
"label" => $row2["ScrapDate"],
"value" => $row2["Quantity"],
// "link" => "deptDrillDown.php?Department=".$row["Department"]
)
);
}
$jsonEncodedData2 = json_encode($arrData2);
$columnChart2 = new FusionCharts("column2D", "chart2" , 600, 300, "chart-2", "json", $jsonEncodedData2);
// Render the chart
$columnChart->render();
$columnChart2->render();
// Close the database connection
$dbhandle->close();
}
?>
As of right now, I can get data from the MySQL database and put it into a graph very easily. Now I want to add 1 more dataset, how do I do this?
To dynamically update the chart, following methods turns very useful:
getJSONData: Fetches chart data in the JSON format.
setJSONData: Sets chart data in the JSON data format
A sample implementation is shown in the below snippet. The chart is initially rendered as the default column2d chart. Once the Add Area button is clicked, an area dataset gets visually updated. Similarly on clicking the Add Line button to add a line dataset. The Reset button restores to original column only visual.
var visitChart,
areaBtn = document.getElementById('area'),
lineBtn = document.getElementById('line'),
resetBtn = document.getElementById('reset');
FusionCharts.ready(function() {
visitChart = new FusionCharts({
type: 'mscombi2d',
renderAt: 'chart-container',
width: '500',
height: '300',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Actual Revenues, Targeted Revenues & Profits",
"subcaption": "Last year",
"xaxisname": "Month",
"yaxisname": "Amount (In USD)",
"numberprefix": "$",
"theme": "fint"
},
"categories": [{
"category": [{
"label": "Jan"
}, {
"label": "Feb"
}, {
"label": "Mar"
}, {
"label": "Apr"
}, {
"label": "May"
}, {
"label": "Jun"
}, {
"label": "Jul"
}, {
"label": "Aug"
}, {
"label": "Sep"
}, {
"label": "Oct"
}, {
"label": "Nov"
}, {
"label": "Dec"
}]
}],
"dataset": [{
"seriesname": "Actual Revenue",
"data": [{
"value": "16000"
}, {
"value": "20000"
}, {
"value": "18000"
}, {
"value": "19000"
}, {
"value": "15000"
}, {
"value": "21000"
}, {
"value": "16000"
}, {
"value": "20000"
}, {
"value": "17000"
}, {
"value": "25000"
}, {
"value": "19000"
}, {
"value": "23000"
}]
}]
}
}).render();
});
areaBtn.addEventListener('click', function() {
var dataset,
json = visitChart.getJSONData();
if (!(dataset = json.dataset)) {
dataset = json.dataset = [];
}
dataset.push({
"seriesname": "Profit",
"renderas": "area",
"showvalues": "0",
"data": [{
"value": "4000"
}, {
"value": "5000"
}, {
"value": "3000"
}, {
"value": "4000"
}, {
"value": "1000"
}, {
"value": "7000"
}, {
"value": "1000"
}, {
"value": "4000"
}, {
"value": "1000"
}, {
"value": "8000"
}, {
"value": "2000"
}, {
"value": "7000"
}]
});
visitChart.setJSONData(json);
areaBtn.disabled = true;
});
lineBtn.addEventListener('click', function() {
var dataset,
json = visitChart.getJSONData();
if (!(dataset = json.dataset)) {
dataset = json.dataset = [];
}
dataset.push({
"seriesname": "Projected Revenue",
"renderas": "line",
"showvalues": "0",
"data": [{
"value": "15000"
}, {
"value": "16000"
}, {
"value": "17000"
}, {
"value": "18000"
}, {
"value": "19000"
}, {
"value": "19000"
}, {
"value": "19000"
}, {
"value": "19000"
}, {
"value": "20000"
}, {
"value": "21000"
}, {
"value": "22000"
}, {
"value": "23000"
}]
});
visitChart.setJSONData(json);
lineBtn.disabled = true;
});
resetBtn.addEventListener('click', function() {
var dataset,
len,
json = visitChart.getJSONData();
if (!(dataset = json.dataset)) {
dataset = json.dataset = [];
}
if ((len = dataset.length) > 1) {
dataset.splice(1, len - 1);
}
visitChart.setJSONData(json);
areaBtn.disabled = false;
lineBtn.disabled = false;
});
<script src="http://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
<script src="http://static.fusioncharts.com/code/latest/themes/fusioncharts.theme.fint.js"></script>
<button id='area'>Add Area</button>
<button id='line'>Add Line</button>
<button id='reset'>Reset</button>
<span id="chart-container">FusionCharts XT will load here!</span>
The data getting appended might be fetched from a database in a similar manner stated above.

Categories