1. 折线图
let chartLineData = {
tooltip: {
trigger: "axis",
axisPointer: {
type: "line",
lineStyle: {
color: "#6A32C9",
width: 2,
type: "dashed"
}
}
},
grid: {
top: 30,
left: "3%",
right: 25,
bottom: "1%",
containLabel: true
},
xAxis: {
type: "category",
name: "月",
nameLocation: "end",
nameTextStyle: {
color: "#666",
fontSize: 12,
fontWeight: "normal",
backgroundColor: "transparent"
},
nameGap: 10,
boundaryGap: false,
axisLine: {
show: true,
lineStyle: {
color: "#999",
width: 1,
type: "solid"
}
},
axisTick: {
show: true,
alignWithLabel: true,
lineStyle: {
color: "#999",
width: 1
}
},
axisLabel: {
show: true,
color: "#666",
fontSize: 12,
rotate: 0,
margin: 10,
formatter: function(value) {
const month = value.split("-")[1];
const monthNum = parseInt(month, 10);
return monthNum;
}
},
data: []
},
yAxis: {
type: "value",
name: "人日",
nameLocation: "end",
nameTextStyle: {
color: "#666",
fontSize: 12,
fontWeight: "normal",
verticalAlign: "bottom",
align: "right",
backgroundColor: "transparent"
},
nameGap: 15,
axisLine: {
show: true,
lineStyle: {
color: "#999",
width: 1
}
},
axisLabel: {
show: true,
color: "#666",
fontSize: 12,
formatter: "{value}"
},
splitLine: {
show: true,
lineStyle: {
color: "#f0f0f0",
width: 1,
type: "solid"
}
}
},
series: []
};
2. 饼状图
let chartPieData = {
color: [
"#4E9CF8",
"#61C9FA",
"#333CA3",
"#EABF5A",
"#DF7C42",
"#C95A48",
"#5D86E5",
"#7CB9C2"
],
tooltip: {
trigger: "item"
},
legend: {
bottom: 10,
left: "center"
},
grid: {
top: 0,
bottom: 100,
left: "10%",
right: "10%",
containLabel: true
},
series: [
{
name: "",
type: "pie",
center: ["50%", "38%"],
radius: ["76%", "52%"],
avoidLabelOverlap: false,
label: {
show: false,
position: "center"
},
emphasis: {
label: {
show: true,
fontSize: 12,
fontWeight: "bold"
}
},
labelLine: {
show: false
},
data: []
}
]
};
3. 柱状图
let chartBarData = {
color: ["#99E0FC", "#50B0F9", "#3A6DF6"],
tooltip: {
trigger: "item"
},
legend: {
// selectedMode: false,
bottom: 10,
left: "center"
},
grid: {
top: 5,
left: "3%",
right: "3%",
bottom: 40,
containLabel: true
},
yAxis: {
type: "value",
// Y轴轴线颜色
axisLine: {
show: true,
lineStyle: {
color: "#999",
width: 1
}
},
axisLabel: {
show: true,
color: "#666",
fontSize: 12,
formatter: "{value}"
},
splitLine: {
show: true,
lineStyle: {
color: "#f0f0f0",
width: 1,
type: "solid"
}
}
},
xAxis: {
type: "category",
data: [],
// boundaryGap: false, // 取消两端留白
// X轴轴线颜色
axisLine: {
show: true, // 是否显示轴线
lineStyle: {
color: "#999",
width: 1,
type: "solid"
}
},
axisTick: {
show: true, // 是否显示刻度
alignWithLabel: true, // 刻度与标签对齐
lineStyle: {
color: "#999",
width: 1
}
},
axisLabel: {
show: true,
color: "#666",
fontSize: 12,
rotate: 0,
margin: 10,
formatter: function(value) {
const month = value.split("-")[1];
const monthNum = parseInt(month, 10);
return monthNum + "月";
}
}
},
series: []
};
4. 折线图series中的某一项
let serie = {
data: [],
type: "line",
smooth: true,
name: "",
showSymbol: false,
emphasis: {
showSymbol: true,
symbolSize: 12,
itemStyle: {
borderColor: "#4A75E4",
borderWidth: 3
}
},
lineStyle: {
color: {
type: "linear",
x: 0,
y: 0,
x2: 1,
y2: 0,
colorStops: [
{ offset: 0, color: "#6BE0FB" },
{ offset: 0.5, color: "#4D7DF6" },
{ offset: 1, color: "#6944F2" }
]
}
},
areaStyle: {
color: {
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{ offset: 0, color: "rgba(229, 238, 254, 0.7)" },
{ offset: 0.5, color: "rgba(229, 238, 254, 0.5)" },
{ offset: 1, color: "rgba(229, 238, 254, 0)" }
],
global: false
}
}
};
5. tooltip 设置 formatter
options.tooltip.formatter = function(params) {
let result = params[0].name + "<br/>";
params.forEach(function(item) {
const percentValue = item.value + "%";
const colorDot = `<span style="
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: ${item.color};
margin-right: 6px;
vertical-align: middle;
"></span>`;
result += colorDot + item.seriesName + ": " + percentValue + "<br/>";
});
return result;
}
6. x轴间隔显示
options.xAxis.axisLabel = {
interval: 4
};
7. 格式化Y轴
options.yAxis.axisLabel = {
formatter: function(value) {
if (value >= 1000) {
const kValue = value / 1000;
return kValue % 1 === 0 ? kValue + "k" : kValue.toFixed(1) + "k";
}
return value;
},
color: "#666",
fontSize: 12
};
8. legend 设置样式为圆圈,以及文字样式
let legend = {
orient: "vertical",
left: "72%",
top: "middle",
textStyle: {
color: "#333",
fontSize: 11,
fontWeight: "normal",
align: "left",
verticalAlign: "middle",
lineHeight: 12
},
icon: "circle",
itemWidth: 6,
itemHeight: 6,
itemGap: 10
};