-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
007e93c
commit 14f3af8
Showing
5 changed files
with
70 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 22 additions & 25 deletions
47
src/app/components/qunicorn-app/histogram-plot/histogram-plot.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,66 @@ | ||
import { Component, OnChanges, OnInit, ViewChild, Input } from '@angular/core'; | ||
import { Chart } from 'chart.js'; | ||
|
||
|
||
|
||
@Component({ | ||
selector: 'app-histogram-plot', | ||
templateUrl: './histogram-plot.component.html', | ||
styleUrls: ['./histogram-plot.component.scss'] | ||
styleUrls: ['./histogram-plot.component.scss'], | ||
}) | ||
export class HistogramPlotComponent implements OnChanges { | ||
|
||
@ViewChild('plot', { static: true }) plotDiv; | ||
|
||
@Input() counts: { [props: string]: number } | null = null; | ||
|
||
constructor() { } | ||
constructor() {} | ||
|
||
ngOnChanges(): void { | ||
|
||
const labels = Object.keys(this.counts); | ||
|
||
const countsData = []; | ||
labels.forEach(label => countsData.push(this.counts[label])); | ||
labels.forEach((label) => countsData.push(this.counts[label])); | ||
|
||
console.log(labels, countsData); | ||
|
||
const data = { | ||
labels: labels,//Object.keys(this.counts), | ||
labels, // Object.keys(this.counts), | ||
datasets: [ | ||
{ | ||
label: 'Counts', | ||
data: countsData,// Object.values(this.counts), | ||
backgroundColor: "#3f51b5" | ||
data: countsData, // Object.values(this.counts), | ||
backgroundColor: '#3f51b5', | ||
}, | ||
] | ||
], | ||
}; | ||
|
||
const config = { | ||
type: 'bar', | ||
data: data, | ||
data, | ||
options: { | ||
scales: { | ||
yAxes: [{ | ||
yAxes: [ | ||
{ | ||
ticks: { | ||
beginAtZero: true, | ||
min: 0, | ||
} | ||
}] | ||
} | ||
beginAtZero: true, | ||
min: 0, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
} | ||
}; | ||
|
||
const div: HTMLDivElement = this.plotDiv.nativeElement; | ||
div.innerHTML = ""; | ||
const canvas = document.createElement("canvas"); | ||
canvas.setAttribute("height", "50px"); | ||
canvas.setAttribute("width", "50px"); | ||
div.innerHTML = ''; | ||
const canvas = document.createElement('canvas'); | ||
canvas.setAttribute('height', '50px'); | ||
canvas.setAttribute('width', '50px'); | ||
canvas.width = 500; | ||
canvas.height = 300; | ||
const context = canvas.getContext('2d'); | ||
context.scale(0.5, 0.5); | ||
//chartcontext.scale(50, 50); | ||
// chartcontext.scale(50, 50); | ||
div.appendChild(canvas); | ||
|
||
new Chart(context, config); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters