美文网首页
echart 画图技巧汇总

echart 画图技巧汇总

作者: sisselxie | 来源:发表于2021-01-14 13:18 被阅读0次

1.饼图中间画文字


image.png
let myChart = this.$echarts.init(pieChart);
     let options = {
       tooltip: {
         trigger: "item",
         formatter: "{a} <br/>{b}: {c} ({d}%)",
       },
       title: {                                          //title和graphic 中间画文字
         text: this.totalCount,
         left: "center",
         top: "40%",
         textStyle: {
           color: "#545a68",
           fontSize: 26,
           align: "center",
         },
       },
       graphic: {
         type: "text",
         left: "center",
         top: "54%",
         style: {
           text: "总摊位数",
           textAlign: "center",
           color: "#545a68",
           fill: "#333",
           fontSize: 14,
           align: "center",
         },
       },

       series: [
         {
           name: "摊位",
           type: "pie",
           radius: ["40%", "70%"],
           labelLine: {
             length: 20,
             length2: 0,
           },
           label: {         //动态lable
             formatter: function (data) {
               if (data.name === "未租赁") {
                 return "{c|" + data.value + "}个\n{hr|}\n {b|" + data.name + "}";
               } else {
                 return "{c|" + data.value + "}个\n{hr1|}\n {b|" + data.name + "}";
               }
             },
             fontSize: 16,
             padding: [0, -3],
             rich: {
               c: {
                 fontSize: 24,
                 lineHeight: 33,
               },
               hr: {
                 borderColor: "#545a68",
                 width: "100%",
                 borderWidth: 1,
                 height: 0,
               },
               hr1: {
                 borderColor: "#43b748",
                 width: "100%",
                 borderWidth: 1,
                 height: 0,
               },
               b: {
                 fontSize: 16,
                 lineHeight: 33,
               },
             },
           },
           legendHoverLink: false,
           hoverAnimation: false,
           itemStyle: {
             borderColor: "#ffffff",
             borderWidth: 3,
           },
           data: data,
         },
       ],
       color: ["#43b748", "#545a68"],
     };
     myChart.setOption(options);

2.柱状图圆角和lable自定义


image.png
 let myChart = this.$echarts.init(barChart);
      let options = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器,坐标轴触发有效
            type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
          },
        },
        legend: {                    
          data: ["已租赁", "未租赁"],
          right: "3%",
        },
        grid: {
          left: "3%",
          right: "3%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: data.labelArr,
            axisTick: {
              show: false,
            },
            axisLine: {
              lineStyle: {
                width: 0,
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: ["#f4f9f9"],
                width: 1,
                type: "solid",
              },
            },
            axisLabel: {
              interval: 0,
              lineHeight: 16,
              formatter: function (params) {        //自定义label
                var arr, newParamsName;
                arr = params.split("-");
                if (arr.length > 1) {
                  newParamsName = arr[0] + "-\n" + arr[1];
                } else {
                  newParamsName = params;
                }
                return newParamsName;
              },
            },
          },
        ],

        yAxis: [
          {
            type: "value",
            axisTick: {
              show: false,
            },
            axisLine: {
              lineStyle: {
                width: 0,
              },
            },
            splitLine: {
              show: true,
              lineStyle: {
                color: ["#dee4e5"],
                width: 1,
                type: "solid",
              },
            },
          },
        ],
        series: [
          {
            name: "已租赁",
            type: "bar",
            barWidth: 16,
            data: data.rentedCountArr,
            itemStyle: {
              barBorderRadius: [4, 4, 0, 0],     //bar圆角

            },
          },
          {
            name: "未租赁",
            type: "bar",
            barWidth: 16,
            data: data.notRentedCountArr,
            itemStyle: {
              barBorderRadius: [4, 4, 0, 0],
            },
          },
        ],
        color: ["#43b748", "#b5c7d0"],
      };

      myChart.setOption(options);

相关文章

  • echart 画图技巧汇总

    1.饼图中间画文字 2.柱状图圆角和lable自定义

  • echarts

    echart 入门教程 http://www.imooc.com/view/687 一.浏览器画图原理简介 1.C...

  • React Native Echart 问题汇总

    1. width 和 height 设置的不对的时候,会出现边框线如图所示: 解决办法:Echarts/index...

  • echart启航

    构建简单echart图表:参考:Echart官网 查看官方文档说明 下载echart脚本Echart官方网站 下载...

  • 初始化echarts

    一、初始化 二、渲染/画图 三、关于性能 echart在性能方面很不友好,所以在退出页面的时候一定要销毁echar...

  • OL3和echart的结合

    概述 本文讲述OL3结合echart,实现echart中的炫酷特效。 效果 echart3 echart2 说明:...

  • Angular2 ngx-eChart的导入使用

    引入ngx-eChart 安装echart包、ngx-echart包 angular.json中引入echarts...

  • vue组建之——模拟K线数据

    子组建: // Echart图表 import Echart...

  • echarts 相关label配置

    eacarts API 配置项:echart API echart option配置项 let option =...

  • 2019-04-14持续疲劳

    今日自省: 如何能提高画图的速度? 画图速度慢是没想好还是工具不熟悉? 在这里开一个文集,分享画图的技巧,并分享一...

网友评论

      本文标题:echart 画图技巧汇总

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