配置项:
const chartOption = {
tooltip: {
trigger: "axis",
axisPointer: {
// 坐标轴指示器,坐标轴触发有效
type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
},
formatter: function (params) {
var str = params[0].name + "<br>";
for (let item of params) {
str += item.seriesName + " : " + item.value + "%<br>";
}
return str;
},
},
legend: {
data: ["看涨", "看稳", "看跌"],
},
grid: {
bottom: 10,
left: 10,
top: 25,
containLabel: true,
},
xAxis: {
type: "value",
show: false,
},
yAxis: {
type: "category",
data: [],
//隐藏坐标线
axisLine: {
show: false,
},
//隐藏刻度线
axisTick: {
show: false,
},
},
series: [
{
name: "看涨",
type: "bar",
stack: "total",
label: {
show: true,
formatter: "{c}%",
},
itemStyle: {
color: "#e43d30",
},
data: [],
},
{
name: "看稳",
type: "bar",
stack: "total",
label: {
show: true,
formatter: "{c}%",
},
itemStyle: {
color: "#1ba035",
},
data: [],
},
{
name: "看跌",
type: "bar",
stack: "total",
label: {
show: true,
formatter: "{c}%",
},
itemStyle: {
color: "#868686",
},
data: [],
// barWidth: 10, // 柱子宽度
},
],
};
处理数据时遇到百分比之和不为100的情况:js百分比之和不等于一百-CSDN博客