const offsetX = 16;
const offsetY = 8;
[-18, 18].forEach((customOffset, index) => {
const CubeLeft = echarts.graphic.extendShape({
shape: {
x: 0,
y: 0,
},
buildPath: function (ctx, shape) {
const xAxisPoint = shape.xAxisPoint;
const c0 = [shape.x - customOffset, shape.y];
const c1 = [shape.x - offsetX - customOffset, shape.y - offsetY];
const c2 = [xAxisPoint[0] - offsetX - customOffset, xAxisPoint[1] - offsetY];
const c3 = [xAxisPoint[0] - customOffset, xAxisPoint[1]];
ctx.moveTo(c0[0], c0[1]).lineTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).closePath();
},
});
const CubeRight = echarts.graphic.extendShape({
shape: {
x: 0,
y: 0,
},
buildPath: function (ctx, shape) {
const xAxisPoint = shape.xAxisPoint;
const c1 = [shape.x - customOffset, shape.y];
const c2 = [xAxisPoint[0] - customOffset, xAxisPoint[1]];
const c3 = [xAxisPoint[0] + offsetX - customOffset, xAxisPoint[1] - offsetY];
const c4 = [shape.x + offsetX - customOffset, shape.y - offsetY];
ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath();
},
});
const CubeTop = echarts.graphic.extendShape({
shape: {
x: 0,
y: 0,
},
buildPath: function (ctx, shape) {
const c1 = [shape.x - customOffset, shape.y];
const c2 = [shape.x + offsetX - customOffset, shape.y - offsetY];
const c3 = [shape.x - customOffset, shape.y - offsetX];
const c4 = [shape.x - offsetX - customOffset, shape.y - offsetY];
ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath();
},
});
echarts.graphic.registerShape('CubeLeft' + index, CubeLeft);
echarts.graphic.registerShape('CubeRight' + index, CubeRight);
echarts.graphic.registerShape('CubeTop' + index, CubeTop);
});
const MAX =[ 800, 800, 800, 800, 800, 800, 800];
const NAME = [2015, 2016, 2017, 2018, 2019, 2020, 2021];
const VALUE = [200, 400, 300, 500, 700, 300, 100];
const VALUE2 = [500, 200, 700, 400, 300, 600, 400];
option = {
backgroundColor: '#012366',
grid: {
left: '5%',
right: 0,
bottom: '5%',
top: '5%',
containLabel: true,
},
tooltip: {
trigger: 'axis',
axisPointer : { // 坐标轴指示器,坐标轴触发有效
type : 'shadow' // 默认为直线,可选为:'line' | 'shadow'
},
formatter: function(e) {
var str =
e[2].axisValue +
"<br>" +
"<span style='display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:" +
"rgba(225,155,172, 1)" +
";'></span>" +
"课程数量 : " +
e[2].value +
"<br>" +
"<span style='display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:" +
"rgba(25,155,172, 1)" +
";'></span>" +
"完成数量 : " +
e[3].value;
return str;
},
},
legend: {
orient: 'vertical',
x: 'right',
y: 'center',
data: ['课程数量', '完成数量', ]
},
xAxis: {
type: 'category',
data: NAME,
axisLine: {
show: true,
lineStyle: {
width: 2,
color: '#7ca7d9',
},
},
axisTick: {
show: false,
},
axisLabel: {
fontSize: 14,
},
},
yAxis: {
type: 'value',
minInterval: 1,
axisLine: {
show: true,
lineStyle: {
width: 2,
color: '#2B7BD6',
},
},
splitLine: {
show: true,
lineStyle: {
color: 'rgba(201,217,241,0.23)',
},
},
axisTick: {
show: false,
},
axisLabel: {
fontSize: 14,
},
},
dataZoom: [{
show: true,
height: 30,
xAxisIndex: [
0
],
bottom: 30,
start: 10,
end: 50,
handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
handleSize: '110%',
handleStyle:{
color:"#d3dee5",
},
textStyle:{
color:"#fff"},
borderColor:"#90979c"
}, {
type: "inside",
show: true,
height: 15,
start: 1,
end: 10
}],
series: [
{
// 最大高度
type: 'custom',
renderItem: function(params, api) {
const location = api.coord([api.value(0), api.value(1)])
return {
type: 'group',
children: [{
type: 'CubeLeft0',
shape: {
api,
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0])
},
style: {
fill: `rgba(25,155,172, .1)`
}
}, {
type: 'CubeRight0',
shape: {
api,
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0])
},
style: {
fill: `rgba(25,155,172, .3)`
}
}, {
type: 'CubeTop0',
shape: {
api,
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0])
},
style: {
fill: `rgba(25,155,172, .4)`
}
}]
}
},
data: MAX
} ,
{
// 最大高度
type: 'custom',
renderItem: function(params, api) {
const location = api.coord([api.value(0), api.value(1)])
return {
type: 'group',
children: [{
type: 'CubeLeft1',
shape: {
api,
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0])
},
style: {
fill: `rgba(225,155,172, .1)`
}
}, {
type: 'CubeRight1',
shape: {
api,
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0])
},
style: {
fill: `rgba(225,155,172, .3)`
}
}, {
type: 'CubeTop1',
shape: {
api,
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0])
},
style: {
fill: `rgba(225,155,172, .4)`
}
}]
}
},
data: MAX
} ,
{
type: 'custom',
renderItem: (params, api) => {
const location = api.coord([api.value(0), api.value(1)]);
return {
type: 'group',
children: [
{
type: 'CubeLeft0',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0] - 0,
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(25,155,172, .5)',
},
{
offset: 1,
color: 'rgba(25,155,172, .5)',
},
]),
},
},
{
type: 'CubeRight0',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0] - 0,
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(25,155,172, 1)',
},
{
offset: 1,
color: 'rgba(25,155,172, .5)',
},
]),
},
},
{
type: 'CubeTop0',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0] - 0,
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(25,155,172, .8)',
},
{
offset: 1,
color: 'rgba(25,155,172, .8)',
},
]),
},
},
],
};
},
data: VALUE,
},
{
type: 'custom',
renderItem: (params, api) => {
const location = api.coord([api.value(0), api.value(1)]);
return {
type: 'group',
children: [
{
type: 'CubeLeft1',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0] - 0,
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(225,155,172, .5)',
},
{
offset: 1,
color: 'rgba(225,155,172, .5)',
},
]),
},
},
{
type: 'CubeRight1',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0] - 0,
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(225,155,172, 1)',
},
{
offset: 1,
color: 'rgba(225,155,172, .5)',
},
]),
},
},
{
type: 'CubeTop1',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0] - 0,
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(225,155,172, .8)',
},
{
offset: 1,
color: 'rgba(225,155,172, .8)',
},
]),
},
},
],
};
},
data: VALUE2,
},
],
};
【echarts】3D双柱形图
于 2023-11-06 14:23:22 首次发布