Chart.js 更改折线图中的轴位置
我正试图在离子应用程序中得到一张图表,其中y轴在右边 这就是我所做的 我的代码:Chart.js 更改折线图中的轴位置,chart.js,Chart.js,我正试图在离子应用程序中得到一张图表,其中y轴在右边 这就是我所做的 我的代码: @ViewChild('barChart', {static: true}) BarChart: ElementRef; this.bars = new Chart(this.BarChart.nativeElement, { type: 'line', data: { labels: ['S1', 'S2', 'S3', 'S4',
@ViewChild('barChart', {static: true}) BarChart: ElementRef;
this.bars = new Chart(this.BarChart.nativeElement, {
type: 'line',
data: {
labels: ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8'],
datasets: [{
label: 'Viewers in millions',
data: [2.5, 3.8, 5, 6.9, 6.9, 7.5, 10, 17],
backgroundColor: 'rgba(88, 172, 230, 0)',
borderColor: 'rgb(88, 172, 230)',
borderWidth: 1,
pointBackgroundColor: 'rgb(88, 172, 230)',
pointBorderColor: 'rgb(88, 172, 230)',
pointRadius: 5,
yAxisID: 'right-y-axis',
}]
},
options: {
scales: {
yAxes: [{
ticks: {}
},
{
id: 'right-y-axis',
type: 'linear',
position: 'right'
}]
}
}
});
但我在左边得到了意想不到的数字[-0.1,-0.5….]
我需要做的是:
因此,我需要删除网格线和左边的数字,并将x轴改为反向,这样它从右边开始,而不是从左边开始。你的括号错了。你不需要一个额外的轴,只要改变一个轴的位置
options: {
scales: {
yAxes: [{
position: 'right',
gridLines: {
display: false
}
}],
xAxes: [{
gridLines: {
display: false
}
}]
}
}
如何从两个轴之间的链接开始的位置进行更改,我的意思是我需要蓝色泡泡从右边开始哦,我没读过。您可以使用
labels.reverse()
和data.reverse()
。