Using data received from Backend in Angular Highchart











up vote
0
down vote

favorite












This is how I have been displaying data in a stacked column highchart in angular 5.



series: [{
name: 'DEF',
data: [5, 3, 4, 7, 2]
}, {
name: 'ABC',
data: [2, 2, 3, 2, 1]
}, {
name: 'MNP',
data: [3, 4, 4, 2, 5]
}, {
name: 'ASM',
data: [3, 5, 2, 3, 6]
}, {
name: 'BCC',
data: [2, 5, 3, 4, 6]
}]


Now, I have been trying that on initialization of this component I get data from backend and use it here. I am successful in getting data as shown below but dont know how to use it to display in high charts.



  ngOnInit() {
this.metricService.getPluginMetrics().subscribe(data =>{
this.metricItems = data;
console.log(this.metricItems[0].value);
})
};


This is the console output for the console.log above



Data is fetched from a json file at backend to mock an API for now and then converted into string and this is how the data is being returned.
enter image description here



This is some of the content of JSON file.



[
{
"name": "DEF",
"value": [10, 20, 40, 60, 60],
"type": "",
"timestamp": 1533822125000
},
{
"name": "ABC",
"value": [5, 3, 4, 7, 2, 6],
"type": "",
"timestamp": 1533822125000
}
]


At the angular frontend the object for MetricItem is



export interface MetricItem {
name: string;
value: string;
type: string;
timestamp: string;
}


Also I tried to replace



series: [{
name: 'DEF',
data: [5, 3, 4, 7, 2]
},.......


with



series: [{
name: this.metricItems[0].name,
data: this.metricItems[0].value
}


But this has no effect and chart is not displayed. Could you please tell how to approach this.



EDIT: As @Core972 suggested in comments I replaced



title: {
text: 'Stacked Consumption chart'
}


with this



title: {
text: this.metricItems[0].name
}


but the chart is not displayed.










share|improve this question




















  • 1




    Post a complete minimal example reproducing the issue.
    – JB Nizet
    Nov 4 at 9:53










  • Just to be sure it's a data problem, could you add a title to the chart parameters and look if the title appear. Also Highcharts require data as numbers so check if this.metricItems[0].value are really numbers and not strings.
    – Core972
    Nov 4 at 9:55










  • @Core972 As I mentioned this.metricItems[0].value are actually string. I tried to do JSON.parse() but to no avail.
    – Shaurya
    Nov 4 at 9:58










  • @Core972 I replaced the title with one of the parameters of the data received but the whole chart is not displayed.
    – Shaurya
    Nov 4 at 10:14










  • @Shaurya no, you said that the JSON contains "value": [10, 20, 40, 60, 60]. So it's not a string. It's an array of numbers. Again, post a complete minimal example reproducing the issue.
    – JB Nizet
    Nov 4 at 10:49















up vote
0
down vote

favorite












This is how I have been displaying data in a stacked column highchart in angular 5.



series: [{
name: 'DEF',
data: [5, 3, 4, 7, 2]
}, {
name: 'ABC',
data: [2, 2, 3, 2, 1]
}, {
name: 'MNP',
data: [3, 4, 4, 2, 5]
}, {
name: 'ASM',
data: [3, 5, 2, 3, 6]
}, {
name: 'BCC',
data: [2, 5, 3, 4, 6]
}]


Now, I have been trying that on initialization of this component I get data from backend and use it here. I am successful in getting data as shown below but dont know how to use it to display in high charts.



  ngOnInit() {
this.metricService.getPluginMetrics().subscribe(data =>{
this.metricItems = data;
console.log(this.metricItems[0].value);
})
};


This is the console output for the console.log above



Data is fetched from a json file at backend to mock an API for now and then converted into string and this is how the data is being returned.
enter image description here



This is some of the content of JSON file.



[
{
"name": "DEF",
"value": [10, 20, 40, 60, 60],
"type": "",
"timestamp": 1533822125000
},
{
"name": "ABC",
"value": [5, 3, 4, 7, 2, 6],
"type": "",
"timestamp": 1533822125000
}
]


At the angular frontend the object for MetricItem is



export interface MetricItem {
name: string;
value: string;
type: string;
timestamp: string;
}


Also I tried to replace



series: [{
name: 'DEF',
data: [5, 3, 4, 7, 2]
},.......


with



series: [{
name: this.metricItems[0].name,
data: this.metricItems[0].value
}


But this has no effect and chart is not displayed. Could you please tell how to approach this.



EDIT: As @Core972 suggested in comments I replaced



title: {
text: 'Stacked Consumption chart'
}


with this



title: {
text: this.metricItems[0].name
}


but the chart is not displayed.










share|improve this question




















  • 1




    Post a complete minimal example reproducing the issue.
    – JB Nizet
    Nov 4 at 9:53










  • Just to be sure it's a data problem, could you add a title to the chart parameters and look if the title appear. Also Highcharts require data as numbers so check if this.metricItems[0].value are really numbers and not strings.
    – Core972
    Nov 4 at 9:55










  • @Core972 As I mentioned this.metricItems[0].value are actually string. I tried to do JSON.parse() but to no avail.
    – Shaurya
    Nov 4 at 9:58










  • @Core972 I replaced the title with one of the parameters of the data received but the whole chart is not displayed.
    – Shaurya
    Nov 4 at 10:14










  • @Shaurya no, you said that the JSON contains "value": [10, 20, 40, 60, 60]. So it's not a string. It's an array of numbers. Again, post a complete minimal example reproducing the issue.
    – JB Nizet
    Nov 4 at 10:49













up vote
0
down vote

favorite









up vote
0
down vote

favorite











This is how I have been displaying data in a stacked column highchart in angular 5.



series: [{
name: 'DEF',
data: [5, 3, 4, 7, 2]
}, {
name: 'ABC',
data: [2, 2, 3, 2, 1]
}, {
name: 'MNP',
data: [3, 4, 4, 2, 5]
}, {
name: 'ASM',
data: [3, 5, 2, 3, 6]
}, {
name: 'BCC',
data: [2, 5, 3, 4, 6]
}]


Now, I have been trying that on initialization of this component I get data from backend and use it here. I am successful in getting data as shown below but dont know how to use it to display in high charts.



  ngOnInit() {
this.metricService.getPluginMetrics().subscribe(data =>{
this.metricItems = data;
console.log(this.metricItems[0].value);
})
};


This is the console output for the console.log above



Data is fetched from a json file at backend to mock an API for now and then converted into string and this is how the data is being returned.
enter image description here



This is some of the content of JSON file.



[
{
"name": "DEF",
"value": [10, 20, 40, 60, 60],
"type": "",
"timestamp": 1533822125000
},
{
"name": "ABC",
"value": [5, 3, 4, 7, 2, 6],
"type": "",
"timestamp": 1533822125000
}
]


At the angular frontend the object for MetricItem is



export interface MetricItem {
name: string;
value: string;
type: string;
timestamp: string;
}


Also I tried to replace



series: [{
name: 'DEF',
data: [5, 3, 4, 7, 2]
},.......


with



series: [{
name: this.metricItems[0].name,
data: this.metricItems[0].value
}


But this has no effect and chart is not displayed. Could you please tell how to approach this.



EDIT: As @Core972 suggested in comments I replaced



title: {
text: 'Stacked Consumption chart'
}


with this



title: {
text: this.metricItems[0].name
}


but the chart is not displayed.










share|improve this question















This is how I have been displaying data in a stacked column highchart in angular 5.



series: [{
name: 'DEF',
data: [5, 3, 4, 7, 2]
}, {
name: 'ABC',
data: [2, 2, 3, 2, 1]
}, {
name: 'MNP',
data: [3, 4, 4, 2, 5]
}, {
name: 'ASM',
data: [3, 5, 2, 3, 6]
}, {
name: 'BCC',
data: [2, 5, 3, 4, 6]
}]


Now, I have been trying that on initialization of this component I get data from backend and use it here. I am successful in getting data as shown below but dont know how to use it to display in high charts.



  ngOnInit() {
this.metricService.getPluginMetrics().subscribe(data =>{
this.metricItems = data;
console.log(this.metricItems[0].value);
})
};


This is the console output for the console.log above



Data is fetched from a json file at backend to mock an API for now and then converted into string and this is how the data is being returned.
enter image description here



This is some of the content of JSON file.



[
{
"name": "DEF",
"value": [10, 20, 40, 60, 60],
"type": "",
"timestamp": 1533822125000
},
{
"name": "ABC",
"value": [5, 3, 4, 7, 2, 6],
"type": "",
"timestamp": 1533822125000
}
]


At the angular frontend the object for MetricItem is



export interface MetricItem {
name: string;
value: string;
type: string;
timestamp: string;
}


Also I tried to replace



series: [{
name: 'DEF',
data: [5, 3, 4, 7, 2]
},.......


with



series: [{
name: this.metricItems[0].name,
data: this.metricItems[0].value
}


But this has no effect and chart is not displayed. Could you please tell how to approach this.



EDIT: As @Core972 suggested in comments I replaced



title: {
text: 'Stacked Consumption chart'
}


with this



title: {
text: this.metricItems[0].name
}


but the chart is not displayed.







angular highcharts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 4 at 10:11

























asked Nov 4 at 9:49









Shaurya

1187




1187








  • 1




    Post a complete minimal example reproducing the issue.
    – JB Nizet
    Nov 4 at 9:53










  • Just to be sure it's a data problem, could you add a title to the chart parameters and look if the title appear. Also Highcharts require data as numbers so check if this.metricItems[0].value are really numbers and not strings.
    – Core972
    Nov 4 at 9:55










  • @Core972 As I mentioned this.metricItems[0].value are actually string. I tried to do JSON.parse() but to no avail.
    – Shaurya
    Nov 4 at 9:58










  • @Core972 I replaced the title with one of the parameters of the data received but the whole chart is not displayed.
    – Shaurya
    Nov 4 at 10:14










  • @Shaurya no, you said that the JSON contains "value": [10, 20, 40, 60, 60]. So it's not a string. It's an array of numbers. Again, post a complete minimal example reproducing the issue.
    – JB Nizet
    Nov 4 at 10:49














  • 1




    Post a complete minimal example reproducing the issue.
    – JB Nizet
    Nov 4 at 9:53










  • Just to be sure it's a data problem, could you add a title to the chart parameters and look if the title appear. Also Highcharts require data as numbers so check if this.metricItems[0].value are really numbers and not strings.
    – Core972
    Nov 4 at 9:55










  • @Core972 As I mentioned this.metricItems[0].value are actually string. I tried to do JSON.parse() but to no avail.
    – Shaurya
    Nov 4 at 9:58










  • @Core972 I replaced the title with one of the parameters of the data received but the whole chart is not displayed.
    – Shaurya
    Nov 4 at 10:14










  • @Shaurya no, you said that the JSON contains "value": [10, 20, 40, 60, 60]. So it's not a string. It's an array of numbers. Again, post a complete minimal example reproducing the issue.
    – JB Nizet
    Nov 4 at 10:49








1




1




Post a complete minimal example reproducing the issue.
– JB Nizet
Nov 4 at 9:53




Post a complete minimal example reproducing the issue.
– JB Nizet
Nov 4 at 9:53












Just to be sure it's a data problem, could you add a title to the chart parameters and look if the title appear. Also Highcharts require data as numbers so check if this.metricItems[0].value are really numbers and not strings.
– Core972
Nov 4 at 9:55




Just to be sure it's a data problem, could you add a title to the chart parameters and look if the title appear. Also Highcharts require data as numbers so check if this.metricItems[0].value are really numbers and not strings.
– Core972
Nov 4 at 9:55












@Core972 As I mentioned this.metricItems[0].value are actually string. I tried to do JSON.parse() but to no avail.
– Shaurya
Nov 4 at 9:58




@Core972 As I mentioned this.metricItems[0].value are actually string. I tried to do JSON.parse() but to no avail.
– Shaurya
Nov 4 at 9:58












@Core972 I replaced the title with one of the parameters of the data received but the whole chart is not displayed.
– Shaurya
Nov 4 at 10:14




@Core972 I replaced the title with one of the parameters of the data received but the whole chart is not displayed.
– Shaurya
Nov 4 at 10:14












@Shaurya no, you said that the JSON contains "value": [10, 20, 40, 60, 60]. So it's not a string. It's an array of numbers. Again, post a complete minimal example reproducing the issue.
– JB Nizet
Nov 4 at 10:49




@Shaurya no, you said that the JSON contains "value": [10, 20, 40, 60, 60]. So it's not a string. It's an array of numbers. Again, post a complete minimal example reproducing the issue.
– JB Nizet
Nov 4 at 10:49

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139522%2fusing-data-received-from-backend-in-angular-highchart%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139522%2fusing-data-received-from-backend-in-angular-highchart%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini