<div ref="echartsQinggan" style="width: 100%;height: 100%;"></div>
async getData() {
///调用接口获取数据
this.Count1=[1,2,3]
this.Count2=[4,5,6]
this.Count3=[7,null,8]
this.$nextTick(() => {
this.qinganFun()
})
},
qinganFun() {
// 获取DOM节点并初始化
const hotTheme = this.$echarts.init(this.$refs.echartsQinggan)
const dataArr = {
xdata: this.xData,
Count1: this.Count1,
Count2: this.Count2,
Count3: this.Count3,
}
console.log("dataArr", dataArr);
const offsetX = 16;
const offsetY = 8;
// 绘制左侧面
const CubeLeft = this.$echarts.graphic.extendShape({
shape: {
x: 0,
y: 0,
},
buildPath: function (ctx, shape) {
const xAxisPoint = shape.xAxisPoint;
const c0 = [shape.x, shape.y];
const c1 = [shape.x - offsetX, shape.y - offsetY];
const c2 = [xAxisPoint[0] - offsetX, xAxisPoint[1] - offsetY];
const c3 = [xAxisPoint[0], 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 = this.$echarts.graphic.extendShape({
shape: {
x: 0,
y: 0,
xAxisPoint: 30
},
buildPath: function (ctx, shape) {
const xAxisPoint = shape.xAxisPoint;
const c1 = [shape.x, shape.y];
const c2 = [xAxisPoint[0], xAxisPoint[1]];
const c3 = [xAxisPoint[0] + offsetX, xAxisPoint[1] - offsetY];
const c4 = [shape.x + offsetX, 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 = this.$echarts.graphic.extendShape({
shape: {
x: 0,
y: 0,
},
buildPath: function (ctx, shape) {
const c1 = [shape.x, shape.y];
const c2 = [shape.x + offsetX, shape.y - offsetY]; //右点
const c3 = [shape.x, shape.y - offsetX];
const c4 = [shape.x - offsetX, 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();
},
});
// 注册三个面图形
this.$echarts.graphic.registerShape('CubeLeft', CubeLeft);
this.$echarts.graphic.registerShape('CubeRight', CubeRight);
this.$echarts.graphic.registerShape('CubeTop', CubeTop);
hotTheme.setOption({
tooltip: {
trigger: 'axis',
.........
//如果你的 tooltip要重新规定颜色可以用formatter
},
legend: {
............
//如果你的legend要重新规定颜色可以把颜色放到data属性里
},
grid: {
...........
},
xAxis: {
data: dataArr.xdata,
..........
},
yAxis: {
type: 'value',
..........
},
//根据你要展示几根柱子算自己的偏移量
series: [
{
name: 'a',
type: 'custom',
renderItem: (params, api) => {
const location = api.coord([api.value(0), api.value(1)]);
return {
type: 'group',
// x: render_x,
x:this.offset1[params.dataIndex], //根据函数的索引动态改变索引为null时柱子的偏移量
z: 1,
// z:20,
children: [
{
type: 'CubeLeft',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(16, 115, 191, 1)',
},
{
offset: 1,
color: 'rgba(21, 202, 203, 1)',
}
]),
},
},
{
type: 'CubeRight',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(21, 140, 232, 1)',
},
{
offset: 1,
color: 'rgba(30, 244, 245, 1)',
},
]),
},
},
{
type: 'CubeTop',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(23, 152, 252, 1)',
},
{
offset: 1,
color: 'rgba(23, 152, 252, 1)',
},
]),
},
},
],
};
},
data:dataArr.Count1,
},
{
name: 'b',
type: 'custom',
renderItem: (params, api) => {
const location = api.coord([api.value(0), api.value(1)]);
return {
type: 'group',
x:this.offset2[params.dataIndex],
z: 2,
// barWidth: 30,
children: [
{
type: 'CubeLeft',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(196, 116, 45, 1)',
},
{
offset: 1,
color: 'rgba(255, 194, 56, 1)',
}
]),
},
},
{
type: 'CubeRight',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(230, 136, 53, 1)',
},
{
offset: 1,
color: 'rgba(253, 209, 108, 1)',
},
]),
},
},
{
type: 'CubeTop',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(241, 175, 61, 1)',
},
{
offset: 1,
color: 'rgba(241, 175, 61, 1)',
},
]),
},
},
],
};
},
data: dataArr.Count2,
},
{
name: 'c',
type: 'custom',
renderItem: (params, api) => {
const location = api.coord([api.value(0), api.value(1)]);
return {
type: 'group',
x: 0,
z: 3,
// z:15,
children: [
{
type: 'CubeLeft',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(13, 189, 119, 1)',
},
{
offset: 1,
color: 'rgba(54, 221, 154, 1)',
}
]),
},
},
{
type: 'CubeRight',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(17, 202, 128, 1)',
},
{
offset: 1,
color: 'rgba(73, 224, 164, 1)',
},
]),
},
},
{
type: 'CubeTop',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(35, 205, 137, 1)',
},
{
offset: 1,
color: 'rgba(35, 205, 137, 1)',
},
]),
},
},
],
};
},
data: dataArr.Count3,
},
]
})
}
}
}文章来源:https://www.toymoban.com/news/detail-841123.html
</script>文章来源地址https://www.toymoban.com/news/detail-841123.html
到了这里,关于echarts5 3D柱状图的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!