要为ApexCharts堆叠柱状图系列指定特定的颜色,您可以使用colors
选项。以下是一个示例代码,演示如何指定堆叠柱状图系列的颜色:
// 引入ApexCharts库
import ApexCharts from 'apexcharts';
// 数据示例
const seriesData = [{
name: '系列1',
data: [44, 55, 41, 67, 22]
}, {
name: '系列2',
data: [13, 23, 20, 8, 13]
}, {
name: '系列3',
data: [11, 17, 15, 15, 21]
}];
// 颜色示例
const colors = ['#008FFB', '#00E396', '#FEB019'];
// 图表选项
const options = {
chart: {
type: 'bar',
height: 350,
stacked: true,
},
plotOptions: {
bar: {
horizontal: false,
},
},
series: seriesData,
colors: colors,
xaxis: {
categories: ['一月', '二月', '三月', '四月', '五月'],
},
legend: {
position: 'top',
},
};
// 创建图表
const chart = new ApexCharts(document.querySelector('#chart'), options);
// 渲染图表
chart.render();
在上面的示例中,我们首先导入ApexCharts库,并定义了一个seriesData
数组,其中包含三个系列的数据。然后,我们定义了一个colors
数组,其中包含了三个特定的颜色。接下来,我们创建了一个options
对象,其中指定了图表的类型为堆叠柱状图,并将series
和colors
选项设置为我们定义的数据和颜色。最后,我们使用new ApexCharts()
创建一个图表实例,并使用render()
方法渲染图表。
您可以根据需要调整seriesData
和colors
数组中的数据和颜色,以适应您的实际需求。