Charts Chart.JS数据标签与图表图例重叠
在我的图表上,数据标签与图表顶部的图例重叠 这是我的密码:Charts Chart.JS数据标签与图表图例重叠,charts,chart.js,Charts,Chart.js,在我的图表上,数据标签与图表顶部的图例重叠 这是我的密码: type: 'bar', data: { datasets: [ { type:"bar", yAxisID: 'left-y-axis', //barThickness: 24, label: 'Почасовой',
type: 'bar',
data: {
datasets: [
{
type:"bar",
yAxisID: 'left-y-axis',
//barThickness: 24,
label: 'Почасовой',
data: y1,
backgroundColor: 'rgba(54, 162, 135, 0.2)', //'rgba(75,192, 192, 0.2)',
borderColor: 'rgba(54, 162, 135, 0.2)',
borderWidth: 1,
datalabels: {
align: 'center',
anchor: 'center',
//backgroundColor: 'rgba(54, 162, 135, 0.1)',
//function(context) {return context.dataset.backgroundColor;},
borderRadius: 4,
color: 'rgba(54, 162, 135, 0.8)',//'rgba(75,192, 192, 0.8)',
formatter: function(value, context) {
if (value > 0)
return "+" + Math.round(value)
else
return Math.round(value)
},
display: function(context) {
return context.dataset.data[context.dataIndex] != 0; // or >= 1 or ...
}
}
},
{
type:"line",
yAxisID: 'left-y-axis',
label: 'Накопительный',
data: y2,
backgroundColor: 'rgba(255, 255, 255, 0.2)',
borderColor: 'rgba(54, 162, 135, 1)',
borderWidth: 2,
lineTension: 0.3,
datalabels: {
//display: false,
align: 'end',
anchor: 'end',
color: 'rgba(54, 162, 135, 1)', //'rgba(75,192, 192, 1)',
}
},
{
type:"line",
/*
type: 'candlestick',
data: {
datasets: [{
label: 'CHRT - Chart.js Corporation',
data: getRandomData(initialDateStr, barCount)
}]
},
*/
yAxisID: 'right-y-axis',
//barThickness: 24,
label: 'Индекс ММВБ',
data: m,
backgroundColor: 'rgba(255, 255, 255, 0.2)',
borderColor: 'rgba(245, 120, 81, 0.5)', //'rgba(14, 67, 96, 0.2)', //'rgba(234, 78, 106, 0.2)',
borderDash: [20, 3, 3, 3, 3, 3, 3, 3],
borderWidth: 1,
datalabels: {
display: false,
}
},
],
labels: x,
},
options: {
title: {
display: true,
text: 'График доходности за ' + title,
fontColor: 'rgba(104, 143, 133, 1)',
fontSize: '16',
},
legend: {
display: true,
labels: {
fontColor: 'rgba(54, 162, 135, 1)',
//padding: 50, //'2, 3, 4, 5',
},
},
scales: {
yAxes: [
{
id: 'left-y-axis',
position: 'left',
//stacked: false,
ticks: {
beginAtZero: true,
callback: (value) => value + "₽",
fontColor: 'rgba(104, 143, 133, 1)',
//max: cum + cum/5,
//padding: 25,
},
gridLines: {
color: 'rgba(104, 143, 133, 0.2)',
zeroLineColor: 'rgba(104, 143, 133, 0.5)',
},
},
{
id: 'right-y-axis',
position: 'right',
gridLines: {
display: false,
},
ticks: {
fontColor: 'rgba(245, 120, 81, 0.8)',
},
}
],
xAxes: [
{
//stacked: true,
gridLines: {
color: 'rgba(104, 143, 133, 0.2)',
zeroLineColor: 'rgba(104, 143, 133, 0.5)',
//tickMarkLength: 15
},
ticks: {
fontColor: 'rgba(104, 143, 133, 1)',
},
}
],
},
plugins: {
},
}
我怎样才能在图例后面留出一些空间,或者把线放低一点,这样图形就不会突出。我唯一能做的就是设置Y轴的最大值:
scales: {
yAxes: [
{
id: 'left-y-axis',
position: 'left',
//stacked: false,
ticks: {
beginAtZero: true,
callback: (value) => value + "₽",
fontColor: 'rgba(104, 143, 133, 1)',
max: maxValFromDataSet + maxValFromDataSet/5,
...
但这看起来不太整洁,因为Y轴的最后一个顶部台阶较小:
这是否回答了您的问题?这回答了你的问题吗?