Fill Chart dynamically with variables from Component
up vote
0
down vote
favorite
i am new to Angular so i think i'm missing something.
i have 3 variables in my component, those variables are being filled after calling .subscribe method on an observable object.
like this
this.interRetard = this.technicienService.getInterRetard(id).subscribe(data => {
this.interRetard = data;
});
the interRetard variable contains a number, i can display its value in the html by doing {{interRetard}} .
the problem is that when i try to display it with console.log() it says :
Subscriber {closed: false, _parent: null, _parents: null, _subscriptions: Array(1), syncErrorValue: null, …}
and i need it to give me the exact value like it is displaying it in the html so i can assign it to the chart like this
public doughnutChartData:number = [this.interRetard , 5, 10];
Thank you.
angular typescript
add a comment |
up vote
0
down vote
favorite
i am new to Angular so i think i'm missing something.
i have 3 variables in my component, those variables are being filled after calling .subscribe method on an observable object.
like this
this.interRetard = this.technicienService.getInterRetard(id).subscribe(data => {
this.interRetard = data;
});
the interRetard variable contains a number, i can display its value in the html by doing {{interRetard}} .
the problem is that when i try to display it with console.log() it says :
Subscriber {closed: false, _parent: null, _parents: null, _subscriptions: Array(1), syncErrorValue: null, …}
and i need it to give me the exact value like it is displaying it in the html so i can assign it to the chart like this
public doughnutChartData:number = [this.interRetard , 5, 10];
Thank you.
angular typescript
1
You seem to be usingthis.interRetard
2 times. Once to hold the subscription returned by the subscribe, and again when you assigndata
to it inside the subscribe.
– R. Richards
Nov 21 at 18:34
1
this.interRetard
is being assigned twice in your statement. You only need to assign it inside thesubscribe
callback.
– Wrokar
Nov 21 at 18:34
i removed it and something weird is happepning :/ when i do console.log(interRetard) it displayes undefined then when i trigger the method again (selection changed of a select box) it shows the right value :/ :/
– kmar akrout
Nov 21 at 18:41
What is the type of yourinterRetard
?
– Rahul Swamynathan
Nov 21 at 18:43
the type is any .. i have bad news also this is not working doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:46
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i am new to Angular so i think i'm missing something.
i have 3 variables in my component, those variables are being filled after calling .subscribe method on an observable object.
like this
this.interRetard = this.technicienService.getInterRetard(id).subscribe(data => {
this.interRetard = data;
});
the interRetard variable contains a number, i can display its value in the html by doing {{interRetard}} .
the problem is that when i try to display it with console.log() it says :
Subscriber {closed: false, _parent: null, _parents: null, _subscriptions: Array(1), syncErrorValue: null, …}
and i need it to give me the exact value like it is displaying it in the html so i can assign it to the chart like this
public doughnutChartData:number = [this.interRetard , 5, 10];
Thank you.
angular typescript
i am new to Angular so i think i'm missing something.
i have 3 variables in my component, those variables are being filled after calling .subscribe method on an observable object.
like this
this.interRetard = this.technicienService.getInterRetard(id).subscribe(data => {
this.interRetard = data;
});
the interRetard variable contains a number, i can display its value in the html by doing {{interRetard}} .
the problem is that when i try to display it with console.log() it says :
Subscriber {closed: false, _parent: null, _parents: null, _subscriptions: Array(1), syncErrorValue: null, …}
and i need it to give me the exact value like it is displaying it in the html so i can assign it to the chart like this
public doughnutChartData:number = [this.interRetard , 5, 10];
Thank you.
angular typescript
angular typescript
asked Nov 21 at 18:29
kmar akrout
298
298
1
You seem to be usingthis.interRetard
2 times. Once to hold the subscription returned by the subscribe, and again when you assigndata
to it inside the subscribe.
– R. Richards
Nov 21 at 18:34
1
this.interRetard
is being assigned twice in your statement. You only need to assign it inside thesubscribe
callback.
– Wrokar
Nov 21 at 18:34
i removed it and something weird is happepning :/ when i do console.log(interRetard) it displayes undefined then when i trigger the method again (selection changed of a select box) it shows the right value :/ :/
– kmar akrout
Nov 21 at 18:41
What is the type of yourinterRetard
?
– Rahul Swamynathan
Nov 21 at 18:43
the type is any .. i have bad news also this is not working doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:46
add a comment |
1
You seem to be usingthis.interRetard
2 times. Once to hold the subscription returned by the subscribe, and again when you assigndata
to it inside the subscribe.
– R. Richards
Nov 21 at 18:34
1
this.interRetard
is being assigned twice in your statement. You only need to assign it inside thesubscribe
callback.
– Wrokar
Nov 21 at 18:34
i removed it and something weird is happepning :/ when i do console.log(interRetard) it displayes undefined then when i trigger the method again (selection changed of a select box) it shows the right value :/ :/
– kmar akrout
Nov 21 at 18:41
What is the type of yourinterRetard
?
– Rahul Swamynathan
Nov 21 at 18:43
the type is any .. i have bad news also this is not working doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:46
1
1
You seem to be using
this.interRetard
2 times. Once to hold the subscription returned by the subscribe, and again when you assign data
to it inside the subscribe.– R. Richards
Nov 21 at 18:34
You seem to be using
this.interRetard
2 times. Once to hold the subscription returned by the subscribe, and again when you assign data
to it inside the subscribe.– R. Richards
Nov 21 at 18:34
1
1
this.interRetard
is being assigned twice in your statement. You only need to assign it inside the subscribe
callback.– Wrokar
Nov 21 at 18:34
this.interRetard
is being assigned twice in your statement. You only need to assign it inside the subscribe
callback.– Wrokar
Nov 21 at 18:34
i removed it and something weird is happepning :/ when i do console.log(interRetard) it displayes undefined then when i trigger the method again (selection changed of a select box) it shows the right value :/ :/
– kmar akrout
Nov 21 at 18:41
i removed it and something weird is happepning :/ when i do console.log(interRetard) it displayes undefined then when i trigger the method again (selection changed of a select box) it shows the right value :/ :/
– kmar akrout
Nov 21 at 18:41
What is the type of your
interRetard
?– Rahul Swamynathan
Nov 21 at 18:43
What is the type of your
interRetard
?– Rahul Swamynathan
Nov 21 at 18:43
the type is any .. i have bad news also this is not working doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:46
the type is any .. i have bad news also this is not working doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:46
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
This should work:
this.technicienService.getInterRetard(id).subscribe(data => {
this.interRetard = data;
console.log(this.iterRetard);
this.myFunction(this.iterRetard) or this.myFunction(data);
});
myFunction(p) {
// Your Logic //
}
yes i know this works .. but i need the variable outside the method subscribe so i can put it in an array and assign the array to a chart like this ... public doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:52
can you please explain your last comment .. i don't seem to get what u're saying
– kmar akrout
Nov 21 at 18:55
I edited the answer, let me know if that answers your question!
– alokstar
Nov 21 at 18:56
@kmarakrout: that comment was partial, so removed it!
– alokstar
Nov 21 at 19:08
1
no problem .. i think your answer is working .. i'm trying something if it works perfectly i'll let you know .. thanks
– kmar akrout
Nov 21 at 19:23
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
This should work:
this.technicienService.getInterRetard(id).subscribe(data => {
this.interRetard = data;
console.log(this.iterRetard);
this.myFunction(this.iterRetard) or this.myFunction(data);
});
myFunction(p) {
// Your Logic //
}
yes i know this works .. but i need the variable outside the method subscribe so i can put it in an array and assign the array to a chart like this ... public doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:52
can you please explain your last comment .. i don't seem to get what u're saying
– kmar akrout
Nov 21 at 18:55
I edited the answer, let me know if that answers your question!
– alokstar
Nov 21 at 18:56
@kmarakrout: that comment was partial, so removed it!
– alokstar
Nov 21 at 19:08
1
no problem .. i think your answer is working .. i'm trying something if it works perfectly i'll let you know .. thanks
– kmar akrout
Nov 21 at 19:23
|
show 1 more comment
up vote
1
down vote
accepted
This should work:
this.technicienService.getInterRetard(id).subscribe(data => {
this.interRetard = data;
console.log(this.iterRetard);
this.myFunction(this.iterRetard) or this.myFunction(data);
});
myFunction(p) {
// Your Logic //
}
yes i know this works .. but i need the variable outside the method subscribe so i can put it in an array and assign the array to a chart like this ... public doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:52
can you please explain your last comment .. i don't seem to get what u're saying
– kmar akrout
Nov 21 at 18:55
I edited the answer, let me know if that answers your question!
– alokstar
Nov 21 at 18:56
@kmarakrout: that comment was partial, so removed it!
– alokstar
Nov 21 at 19:08
1
no problem .. i think your answer is working .. i'm trying something if it works perfectly i'll let you know .. thanks
– kmar akrout
Nov 21 at 19:23
|
show 1 more comment
up vote
1
down vote
accepted
up vote
1
down vote
accepted
This should work:
this.technicienService.getInterRetard(id).subscribe(data => {
this.interRetard = data;
console.log(this.iterRetard);
this.myFunction(this.iterRetard) or this.myFunction(data);
});
myFunction(p) {
// Your Logic //
}
This should work:
this.technicienService.getInterRetard(id).subscribe(data => {
this.interRetard = data;
console.log(this.iterRetard);
this.myFunction(this.iterRetard) or this.myFunction(data);
});
myFunction(p) {
// Your Logic //
}
edited Nov 21 at 18:56
answered Nov 21 at 18:50
alokstar
45427
45427
yes i know this works .. but i need the variable outside the method subscribe so i can put it in an array and assign the array to a chart like this ... public doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:52
can you please explain your last comment .. i don't seem to get what u're saying
– kmar akrout
Nov 21 at 18:55
I edited the answer, let me know if that answers your question!
– alokstar
Nov 21 at 18:56
@kmarakrout: that comment was partial, so removed it!
– alokstar
Nov 21 at 19:08
1
no problem .. i think your answer is working .. i'm trying something if it works perfectly i'll let you know .. thanks
– kmar akrout
Nov 21 at 19:23
|
show 1 more comment
yes i know this works .. but i need the variable outside the method subscribe so i can put it in an array and assign the array to a chart like this ... public doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:52
can you please explain your last comment .. i don't seem to get what u're saying
– kmar akrout
Nov 21 at 18:55
I edited the answer, let me know if that answers your question!
– alokstar
Nov 21 at 18:56
@kmarakrout: that comment was partial, so removed it!
– alokstar
Nov 21 at 19:08
1
no problem .. i think your answer is working .. i'm trying something if it works perfectly i'll let you know .. thanks
– kmar akrout
Nov 21 at 19:23
yes i know this works .. but i need the variable outside the method subscribe so i can put it in an array and assign the array to a chart like this ... public doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:52
yes i know this works .. but i need the variable outside the method subscribe so i can put it in an array and assign the array to a chart like this ... public doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:52
can you please explain your last comment .. i don't seem to get what u're saying
– kmar akrout
Nov 21 at 18:55
can you please explain your last comment .. i don't seem to get what u're saying
– kmar akrout
Nov 21 at 18:55
I edited the answer, let me know if that answers your question!
– alokstar
Nov 21 at 18:56
I edited the answer, let me know if that answers your question!
– alokstar
Nov 21 at 18:56
@kmarakrout: that comment was partial, so removed it!
– alokstar
Nov 21 at 19:08
@kmarakrout: that comment was partial, so removed it!
– alokstar
Nov 21 at 19:08
1
1
no problem .. i think your answer is working .. i'm trying something if it works perfectly i'll let you know .. thanks
– kmar akrout
Nov 21 at 19:23
no problem .. i think your answer is working .. i'm trying something if it works perfectly i'll let you know .. thanks
– kmar akrout
Nov 21 at 19:23
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418439%2ffill-chart-dynamically-with-variables-from-component%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You seem to be using
this.interRetard
2 times. Once to hold the subscription returned by the subscribe, and again when you assigndata
to it inside the subscribe.– R. Richards
Nov 21 at 18:34
1
this.interRetard
is being assigned twice in your statement. You only need to assign it inside thesubscribe
callback.– Wrokar
Nov 21 at 18:34
i removed it and something weird is happepning :/ when i do console.log(interRetard) it displayes undefined then when i trigger the method again (selection changed of a select box) it shows the right value :/ :/
– kmar akrout
Nov 21 at 18:41
What is the type of your
interRetard
?– Rahul Swamynathan
Nov 21 at 18:43
the type is any .. i have bad news also this is not working doughnutChartData:number = [this.interRetard ,this.interFinie,this.interAvance];
– kmar akrout
Nov 21 at 18:46