Answer the question
In order to leave comments, you need to log in
How to generate a graph when opening a page?
Good evening. I continue to learn Angular. I got to the graphical display of data. Because the template is developed on bootstrap, then I decided to use such a component
. The example uses variables that take values already at the declaration. I understand that I'm asking stupidity, but how can I implement the display of the graph if I calculate the data dynamically.
Those. In my template I use:
<canvas mdbChart
[chartType]="chartType"
[datasets]="chartDatasets"
[labels]="chartLabels"
[colors]="chartColors"
[options]="chartOptions"
[legend]="true"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)">
</canvas>
updateDatasetsAndLabels() {
let dataSets: Array<number> = []
let cLabels: Array<string> = []
let tbackgroundColor: Array<string> = []
let thoverBackgroundColor: Array<string> = []
for(let i = 0; i < this.organization.length; i++) {
dataSets.push(this.organization[i].summa)
cLabels.push(this.organization[i].name)
tbackgroundColor.push(this.abackgroundColor[i])
thoverBackgroundColor.push(this.ahoverBackgroundColor[i])
}
this.chartDatasets = [ { data: dataSets } ]
this.chartLabels = cLabels
this.chartColors = [{backgroundColor: tbackgroundColor, hoverBackgroundColor: thoverBackgroundColor, borderWidth: 2}]
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question