qq_36300972 2022-03-01 16:07 采纳率: 0%
浏览 187
已结题

echarts中使用svg,如何在以下代码中将image图片换成svg

var renderItem = function(params,api){
    const type = api.value(2);
    const voltageLevel = api.value(3);
    const leafNum = api.value(5);
    const direction = api.value(6);
    const x1 = api.value(0);
    const y1 = api.value(1);
    
    const group = {
        type:'group',
        x:50,
        y:0,
        children: []
    };
    if(type == "二卷主变"){
        group.children.push({
            type:'image:',
            x:x1*width+offset2X,
            y:y1*height+offset2Y,
            style:{
                width:width_2,
                height:height_2,
                image:'image:svg.svg'
            }
        });
    } else if( type == "三卷主变"){
        group.children.push({
            type:'image',
            x:x1*width+offset3X,
            y:y1*height+offset3Y,
            style:{
                width:width_3,
                height:height_3,
                image:'img/4.png'
            }
        })
    };
    if(type =='母线'){
        
        switch( direction){
            case '上':
            group.children.push({
                type:'line',
                x:0,
                y:0,
                shape:{
                    x1:x1*width,
                    y1:y1*height+offset3Y,
                    x2:x1*width+width,
                    y2:y1*height+offset3Y
                },
                style:{
                    fill: "#ff0000",
                    lineWidth:2,
                    stroke : "#ff5500",
                }
            });
            break;
            case '下左':
            if(voltageLevel == 10){
                group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+offset3X,
                        y1:offset3Y+width_3+y1*height,
                        x2:x1*width-leafNum*width*0.5,
                        y2:offset3Y+width_3+y1*height
                    },
                    style:{
                        fill: "#ff0000",
                        lineWidth:2,
                        stroke : "#ff5500",
                    }
                });
            }else{
                group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+offset3X,
                        y1:offset3Y+width_3+y1*height,
                        x2:x1*width-leafNum*width,
                        y2:offset3Y+width_3+y1*height
                    },
                    style:{
                        fill: "#ff0000",
                        lineWidth:2,
                        stroke : "#ff5500",
                    }
                });
            }
            break;
            case '下右':
            group.children.push({
                type:'line',
                x:0,
                y:0,
                shape:{
                    x1:x1*width+width-offset3X,
                    y1:offset3Y+width_3+y1*height,
                    x2:x1*width+leafNum*width-offset3X,
                    y2:offset3Y+width_3+y1*height
                },
                style:{
                    fill: "#ff0000",
                    lineWidth:2,
                    stroke : "#ff5500",
                }
            });
            break;
            case '下':
            group.children.push({
                type:'line',
                x:0,
                y:0,
                shape:{
                    x1:x1*width+offset2X,
                    y1:offset3Y+width_3+y1*height,
                    x2:x1*width+width-offset2X,
                    y2:offset3Y+width_3+y1*height
                },
                style:{
                    fill: "#ff0000",
                    lineWidth:2,
                    stroke : "#ff5500",
                }
            });
            break;
            case '上右':
            
            if(voltageLevel == 110){
                group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width,
                        y1:offset3Y+y1*height,
                        x2:x1*width+6*width-offset2X,
                        y2:offset3Y+y1*height
                    },
                    style:{
                        fill: "#ff0000",
                        lineWidth:2,
                        stroke : "#ff5500",
                    }
                });
            }else{
                group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+offset2X,
                        y1:offset3Y+y1*height,
                        x2:x1*width+leafNum*width-offset2X,
                        y2:offset3Y+y1*height
                    },
                    style:{
                        fill: "#ff0000",
                        lineWidth:2,
                        stroke : "#ff5500",
                    }
                });
            }
            
            break;
        }
    }
    if(type == '线路'){
        switch( direction){
            case '上':
            group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+width/2,
                        y1:height_3+offset2Y,
                        x2:x1*width+width/2,
                        y2:height+offset2Y
                    },
                    style:{
                        fill: "#ffff00",
                        lineWidth:5,
                        stroke : "#ffff00",
                    }
            });
            break;
            case '上右':
            group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+leafNum*width/2,
                        y1:y1*height-offset2Y,
                        x2:x1*width+leafNum*width/2,
                        y2:y1*height+offset2Y
                    },
                    style:{
                        fill: "#ffff00",
                        lineWidth:5,
                        stroke : "#ffff00",
                    }
            })
            break;
            case '上右横':
            group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+width,
                        y1:y1*height+offset2Y,
                        x2:x1*width+width,
                        y2:y1*height
                    },
                    style:{
                        fill: "#ffff00",
                        lineWidth:5,
                        stroke : "#ffff00",
                    },
            });
            group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+width,
                        y1:y1*height,
                        x2:x1*width+width+width*1.5,
                        y2:y1*height
                    },
                    style:{
                        fill: "#ffff00",
                        lineWidth:5,
                        stroke : "#ffff00",
                    }
            });
            group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+width+width*1.5,
                        y1:y1*height,
                        x2:x1*width+width+width*1.5,
                        y2:y1*height+offset2Y,
                    },
                    style:{
                        fill: "#ffff00",
                        lineWidth:5,
                        stroke : "#ffff00",
                    }
            });
            break;
            case '上左横':
            group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+width,
                        y1:y1*height+offset2Y,
                        x2:x1*width+width,
                        y2:y1*height
                    },
                    style:{
                        fill: "#ffff00",
                        lineWidth:5,
                        stroke : "#ffff00",
                    },
            });
            group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+width,
                        y1:y1*height,
                        x2:x1*width+width-width*1.5,
                        y2:y1*height
                    },
                    style:{
                        fill: "#ffff00",
                        lineWidth:5,
                        stroke : "#ffff00",
                    }
            });
            group.children.push({
                    type:'line',
                    x:0,
                    y:0,
                    shape:{
                        x1:x1*width+width-width*1.5,
                        y1:y1*height,
                        x2:x1*width+width-width*1.5,
                        y2:y1*height+offset2Y,
                    },
                    style:{
                        fill: "#ffff00",
                        lineWidth:5,
                        stroke : "#ffff00",
                    }
            });
            break;
        }
    };
    return group;
    
}
  • 写回答

3条回答 默认 最新

报告相同问题?

问题事件

  • 系统已结题 3月9日
  • 创建了问题 3月1日

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?