Я использую угловой материал, а для диаграмм я использую Chart.js с помощью ng2-charts
.
Итак, я хочу такой график
https://www.screencast.com/t/JQpzuohgWd
для уточнения мне нужно это в угловых
https://github.com/chartjs/Chart.js/issues/5302 (последняя скрипка)
это тоже, но не ясно (окончательный код очень грязный)
Настройка цвета для гистограммы в ng2-chart
Код: файл TS
ngOnInit() {
var myData = [2, 10, 5, 2, 20, 30, 9];
var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
// The type of chart we want to create
type: 'bar',
// The data for our dataset
data: {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "Monthly goal reached",
backgroundColor: "green",
data: myData.map(function (value) {
return value >= 10 ? value : null
}),
},
{
label: "Monthly goal not reached",
backgroundColor: "red",
data: myData.map(function (value) {
return value < 10 ? value : null
}),
}
]
},
// Configuration options go here
options: {
scales: {
xAxes: [{
stacked: true
}],
yAxes: [{
stacked: true
}]
}
}
});
ОШИБКА:
Property 'getContext' does not exist on type 'HTMLElement'.