Jump to content

Daniii

Members
  • Posts

    31
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Daniii's Achievements

Member

Member (2/5)

0

Reputation

  1. What do you mean. Do I have to make an if statement then? I want that the ones that have false are not displayed @Barand
  2. @Barand Can I filter out certain users if for example "InSped": false, is ?
  3. $getdata = "url"; Output: [ { "id": 0, "moneyamount": 0, "donedate": "2020-12-20T18:29:04.509Z", "bonus": 0, "users": [ { "userObject": { "userName": "string", "id": 0, "spedition": { "id": 0, "name": "string", "shortName": "string", "isRealEco": true }, "inSped": true, "formatName": "string" }, "user": "string", "amount": 0, "unit": "string", "value": "string", "max": 0 } ], "ignoredUsers": [ { "userName": "string", "id": 0, "spedition": { "id": 0, "name": "string", "shortName": "string", "isRealEco": true }, "inSped": true, "formatName": "string" } ], "type": 0, "alrreached": 0, "reached": true, "isActive": true } ]
  4. when i paste my url there i get Notice: Trying to get property 'result' of non-object in C:\xampp\htdocs\dashboard-master\chart2.php on line 5 Notice: Trying to access array offset on value of type null in C:\xampp\htdocs\dashboard-master\chart2.php on line 5 Notice: Trying to get property 'Users' of non-object in C:\xampp\htdocs\dashboard-master\chart2.php on line 5 Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\dashboard-master\chart2.php on line 8 Array ( [0] => Array ( [0] => User [1] => Amount ) )
  5. the errors in the console are due to labels: "{label}"
  6. The array works but the chart not
  7. @gw1500se i only get errors in the console
  8. <?php $url = "myurl"; $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_URL, $url); $getdata = curl_exec($curl); $data = json_decode($getdata); $users = $data->result[0]->Users; $datapoints = array(); foreach($users as $user): $dataPoints[] = array( 'label' => $user->UserObject->UserName, 'y' => $user->Amount); endforeach; echo "<pre>"; print_r($dataPoints); echo "</pre>"; echo json_encode($dataPoints, JSON_FORCE_OBJECT); ?> <!DOCTYPE HTML> <div class="container"> <h2>Chart.js — Pie Chart Demo</h2> <div> <canvas id="myChart"></canvas> </div> </div> <script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script> <script> var ctx = document.getElementById("myChart").getContext('2d'); var myChart = new Chart(ctx, { type: 'pie', data: { labels: "{label}", datasets: [{ backgroundColor: [ "#2ecc71", "#3498db", "#95a5a6", "#9b59b6", "#f1c40f", "#e74c3c", "#34495e" ], data: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?> }] } }); </script> <style> .container { width: 80%; margin: 15px auto; } </style> what is wrong? I can no longer see the chart. Json { "result": [ { "ID": 1, "Users": [ { "UserObject": { "UserName": "User1", "-": { "ID": 1 }, "0": "0" }, "User": "User1", "Amount": 57654456 }, { "UserObject": { "UserName": "User2", "-": { "ID": 1 }, "0": "0" }, "User": "User2", "Amount": 57654456 }, { "UserObject": { "UserName": "User3", "-": { "ID": 1 }, "0": "0" }, "User": "User3", "Amount": 57654456 } ], "Reached": false, "IsActive": true } ], "error": false, "version": 1 }
  9. $url = ""; $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_URL, $url); $getdata = curl_exec($curl); $Object = json_decode($getdata); $myObjectMap1 = $Object->result; $datapoints = array(); foreach($myObjectMap1 as $key => $item): $dataPoints[] = array( 'label' => $item->Users[$key]->UserObject->UserName ,'y' => $item->Users[$key]->Amount ); endforeach; print_r($dataPoints); echo json_encode($dataPoints, JSON_FORCE_OBJECT); ?> Hello in this Array i only get User1 but not the others. How can i fix this { "result": [ { "ID": 1, "Users": [ { "UserObject": { "UserName": "User1", "-": { "ID": 1 }, "0": "0" }, "User": "User1", "Amount": 57654456 }, { "UserObject": { "UserName": "User2", "-": { "ID": 1 }, "0": "0" }, "User": "User2", "Amount": 57654456 }, { "UserObject": { "UserName": "User3", "-": { "ID": 1 }, "0": "0" }, "User": "User3", "Amount": 57654456 } ], "Reached": false, "IsActive": true } ], "error": false, "version": 1 }
  10. I do this with an jsonpathfinder
  11. It works but i get only one user i would get teest1 and test2
  12. <?php $1 = file_get_contents(""); $2 = json_decode($1); $3 = $2->result; var_dump($myData1); foreach($3 as $key => $item): echo $item->Users->UserObject->UserName; endforeach; ?> { "result": [ { "ID": 1, "Users": [ { "UserObject": { "UserName": "test1" }, "...": 2 }, { "UserObject": { "UserName": "test2" }, "...": 2 } ], "IsActive": true } ], "error": false } I get this error Notice: Trying to get property 'UserObject' of non-object in C:\xampp\htdocs\dashboard-master\chart.php on line 10 Notice: Trying to get property 'UserName' of non-object in C:\xampp\htdocs\dashboard-master\chart.php on line 10
  13. yes i think is should be a prepared statement
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.