您好,我正在尝试让图表仅在图表数据对象中显示第二个值。因此,y
是我想要的密钥。感谢您的帮助!
以下是我尝试在图表选项中使用的格式化程序:
optionsABC: {
plugins: {
datalabels: {
formatter: function(value, context) {
return context.chart.datasets.data[1];
}
}
}
}
图表数据
methods: {
fillDataAbc () {
this.datacollectionABC = {
plugins: [ChartDataLabels],
labels: [],
datasets: [
{
label: 'Antecedents',
data:[
{x:'Jun 23 2020', y:2},
{x:'Jun 24 2020', y:4},
{x:'Jun 26 2020', y:5},
{x:'Jun 28 2020', y:2},
{x:'Jun 29 2020', y:10},
{x:'Jun 30 2020', y:5},
{x:'Jul 2 2020', y:2},
{x:'Jul 3 2020', y:4},
{x:'Jul 5 2020', y:5},
{x:'Jul 6 2020', y:2},
{x:'Jul 8 2020', y:10},
{x:'Jul 9 2020', y:5}
],
backgroundColor: 'rgba(197, 219, 242)',
},
{
label:'Consequences',
backgroundColor: 'rgba(0, 124, 137)',
data: [
{x:'Jun 23 2020', y:2},
{x:'Jun 24 2020', y:1},
{x:'Jun 26 2020', y:4},
{x:'Jun 28 2020', y:2},
{x:'Jun 29 2020', y:5},
{x:'Jun 30 2020', y:4},
{x:'Jul 2 2020', y:5},
{x:'Jul 3 2020', y:2},
{x:'Jul 5 2020', y:10},
{x:'Jul 6 2020', y:5}
]
},
]
}
}
}