要在ApexCharts中设置基准值,您可以使用“annotations”属性。以下是一个示例代码:
var options = {
series: [{
name: 'sales',
data: [30, 40, 35, 50, 49, 60, 70, 91, 125]
}],
chart: {
type: 'line',
height: 350
},
annotations: {
yaxis: [{
y: 100,
borderColor: '#999',
label: {
show: true,
text: '基准值'
}
}]
},
dataLabels: {
enabled: true
},
stroke: {
curve: 'smooth'
},
title: {
text: 'Product Sales',
align: 'left'
},
xaxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep']
},
yaxis: {
title: {
text: 'Sales'
}
}
};
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
在这个例子中,我们将y轴的基准值设置为100,并使用“annotations”属性来定义它的样式和标签。您可以根据需要调整基准值的位置和样式。
请注意,您需要将上述代码放入HTML文件中,并将其与ApexCharts库一起使用。