美文网首页
echarts中加载svg,不会d3.js的同学来看看

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

作者: 红太羊_8225 | 来源:发表于2021-07-07 14:17 被阅读0次

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

    npm uninstall echarts --save卸载所有echarts

    npm install echarts@5.1.0 --save  必须这么做

    直接上代码,粘贴就好使

    <div class="echart-all">

                    <div

                      id="administrativeCpsvg2"

                      style="

                        dispaly: flex;

                        height: 1250px;

                        width: 90%;

                        margin-left: 5%;

                        margin-right: 5%;

                        margin-top: 0px;

                      "

                    ></div>

                  </div>

    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的同学来看看

          本文链接:https://www.haomeiwen.com/subject/jtboultx.html