echarts中加载svg,不会d3.js的同学来看看

首先import echarts from "echarts";  替换成import * as echarts from 'echarts';

npm uninstall echarts --save卸载所有echarts

npm install [email protected] --save  必须这么做

直接上代码,粘贴就好使


                

                  id="administrativeCpsvg2"

                  style="

                    dispaly: flex;

                    height: 1250px;

                    width: 90%;

                    margin-left: 5%;

                    margin-right: 5%;

                    margin-top: 0px;

                  "

                >

              


var myChart2 = echarts.init(

            document.getElementById("administrativeCpsvg2")

          );

          if (myChart2 === undefined) {

            myChart2 = echarts.init(

              document.getElementById("administrativeCpsvg2")

            );

          }

          echarts.registerMap("organ_diagram", { svg: `我自己的svg`});

注意:我自己的svg:代码,服务器都可以!!!

var option = {

            tooltip: {},

            geo: {

              left: 10,

              right: "0%",

              map: "organ_diagram",

              selectedMode: "multiple",

              emphasis: {

                focus: "self",

                itemStyle: {

                  color: null,

                },

                label: {

                  position: "bottom",

                  distance: 0,

                  textBorderColor: "#fff",

                  textBorderWidth: 2,

                },

              },

              blur: {},

              select: {

                itemStyle: {

                  color: "#b50205",

                },

                label: {

                  show: false,

                  textBorderColor: "#fff",

                  textBorderWidth: 2,

                },

              },

            },

            // grid: {

            //   left: "60%",

            //   top: "20%",

            //   bottom: "20%",

            // },

            // xAxis: {},

            // yAxis: {

            //   data: [

            //     "Airway",

            //     "Blood",

            //     "Brain",

            //     "Heart",

            //     "Intestine",

            //     "kidney",

            //     "Liver",

            //     "Lung",

            //     "Lymph node",

            //     "Pancreas",

            //   ],

            // },

            // series: [

            //   {

            //     type: "bar",

            //     emphasis: {

            //       focus: "self",

            //     },

            //     data: [121,121,121,121, 321, 141, 52, 198, 289, 139],

            //   },

            // ],

          };

          myChart2.setOption(option);


myChart2.on('click', function (params){

        console.log("1",params);

}

你可能感兴趣的:(echarts中加载svg,不会d3.js的同学来看看)