teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

ついk

2020/10/12 14:19

投稿

otyatya_no_tya
otyatya_no_tya

スコア10

title CHANGED
File without changes
body CHANGED
@@ -23,14 +23,14 @@
23
23
  "name1": "aaaa",
24
24
  "labels": ["aaa", "bbb", "ccc", "ddd", "eee"],
25
25
  "datasets": [{
26
- "labels": "1",
26
+ "labels": "123",
27
27
  "backgroundColor": "RGBA(225, 95, 150, 0.5)",
28
28
  "borderColor": "RGBA(225,95,150, 1)",
29
29
  "borderWidth": 1,
30
30
  "pointBackgroundColor": "RGB(46,106,177)"
31
31
  },
32
32
  {
33
- "labels": "2",
33
+ "labels": "234",
34
34
  "backgroundColor": "RGBA(225, 95, 150, 0.5)",
35
35
  "borderColor": "RGBA(225,95,150, 1)",
36
36
  "borderWidth": 1,

3

追記

2020/10/12 14:19

投稿

otyatya_no_tya
otyatya_no_tya

スコア10

title CHANGED
File without changes
body CHANGED
@@ -55,7 +55,7 @@
55
55
  <p>チャート</p>
56
56
  <?php
57
57
  foreach($arr->data->chart->datasets as $data) {
58
- echo $data->{'labels'}[0];
58
+ echo $data->{'labels'}[1];
59
59
  }
60
60
  $chart = $arr->data->chart;
61
61
  var_dump($chart);

2

追記

2020/10/12 14:18

投稿

otyatya_no_tya
otyatya_no_tya

スコア10

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,7 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
3
  phpでjsonの値を取り出したい。
4
- chart->datasets->labelsの値を取り出したい。
4
+ chart->datasets[1]->labelsの値を取り出したい。
5
5
 
6
6
  ### 発生している問題・エラーメッセージ
7
7
 

1

追記

2020/10/12 14:17

投稿

otyatya_no_tya
otyatya_no_tya

スコア10

title CHANGED
File without changes
body CHANGED
@@ -6,19 +6,9 @@
6
6
  ### 発生している問題・エラーメッセージ
7
7
 
8
8
  ```
9
- Notice: Trying to get property 'datasets' of non-object in C:.php on line 23
9
+ チャート
10
10
 
11
- Notice: Trying to get property 'labels' of non-object in C:.php on line 23
12
-
13
- Notice: Trying to get property 'datasets' of non-object in C:php on line 23
14
-
15
- Notice: Trying to get property 'labels' of non-object in C:.php on line 23
16
-
17
- Notice: Trying to get property 'datasets' of non-object in C:.php on line 23
18
-
19
- Notice: Trying to get property 'labels' of non-object in C:.php on line 23
20
-
21
- object(stdClass)#3 (3) { ["name1"]=> string(4) "aaaa" ["labels"]=> array(5) { [0]=> string(3) "aaa" [1]=> string(3) "bbb" [2]=> string(3) "ccc" [3]=> string(3) "ddd" [4]=> string(3) "eee" } ["datasets"]=> array(2) { [0]=> object(stdClass)#4 (5) { ["labels"]=> string(1) "1" ["backgroundColor"]=> string(23) "RGBA(225, 95, 150, 0.5)" ["borderColor"]=> string(19) "RGBA(225,95,150, 1)" ["borderWidth"]=> int(1) ["pointBackgroundColor"]=> string(15) "RGB(46,106,177)" } [1]=> object(stdClass)#5 (5) { ["labels"]=> string(1) "2" ["backgroundColor"]=> string(23) "RGBA(225, 95, 150, 0.5)" ["borderColor"]=> string(19) "RGBA(225,95,150, 1)" ["borderWidth"]=> int(1) ["pointBackgroundColor"]=> string(15) "RGB(46,106,177)" } } }
11
+ 12
22
12
  ```
23
13
  ### 該当のソースコード
24
14
 
@@ -64,8 +54,8 @@
64
54
  <div>
65
55
  <p>チャート</p>
66
56
  <?php
67
- foreach($arr->data->chart as $chart) {
57
+ foreach($arr->data->chart->datasets as $data) {
68
- echo $chart->{'name1'}->{'labels'};
58
+ echo $data->{'labels'}[0];
69
59
  }
70
60
  $chart = $arr->data->chart;
71
61
  var_dump($chart);