zoukankan      html  css  js  c++  java
  • earch单柱形展示百分比

    如图:

    Line.vue

    <template>
      <div>
        <div style=" 300px; height: 300px" ref="chart" id="chart"></div>
      </div>
    </template>
    <script>
    export default {
      data() {
        return {};
      },
      methods: {
        initCharts() {
          let bookCategoryChart = this.$echarts.init(
            document.getElementById("chart")
          );
          var attackSourcesData = [60];
          let num = 60;
          function attackSourcesDataFmt(sData) {
            var sss = [];
            sData.forEach(function (item) {
              sss.push({
                value: item,
                // itemStyle: itemStyle
              });
            });
            console.log(sss);
            return sss;
          }
          var option = {
            tooltip: {      
              show: true,
              className:'tip',
              textStyle: {
                padding: [0, 0, 0, 0],
              },
              // backgroundColor: "rgba(255,255,255,1)", //背景颜色(此时为默认色)
              formatter: function (val) {
                console.log(val);
                console.log(num);
                if (val.seriesName == "未完成") {
                  val.value = 100 - num;
                }
                return `${val.marker}${val.seriesName}:${val.value}%`;
              },
            },
            legend: {
              show: false,
            },
            xAxis: {
              type: "value",
    
              splitLine: {
                show: false,
              },
              axisLabel: {
                show: false,
              },
              axisTick: {
                show: false,
              },
              axisLine: {
                show: false,
              },
            },
            yAxis: [
              {
                type: "category",
                inverse: true,
                splitLine: {
                  show: false,
                },
                axisTick: {
                  show: false,
                },
                axisLine: {
                  show: false,
                },
                data: [],
                axisLabel: {
                  show: false,
                },
              },
            ],
            series: [
              {
                z: 3,
                name: "完成",
                type: "bar",
                barWidth: "10",
                data: attackSourcesDataFmt(attackSourcesData),
                itemStyle: {
                  normal: {
                    // color: "#ff0000",
                    barBorderRadius: 5,
                  },
                },
              },
              {
                name: "未完成",
                type: "bar",
                barWidth: "10",
                barGap: "-100%",
                data: [100],
                itemStyle: {
                  normal: {
                    // color: "#00ff09",
                    barBorderRadius: 5,
                  },
                },
              },
            ],
          };
          bookCategoryChart.setOption(option);
        },
      },
      mounted() {
        this.initCharts();
      },
    };
    </script>
    <style scoped>
    /deep/ .tip{
      color: aquamarine  ;
      background-color: brown ;
      padding:1px !important;
    }
    </style>
    集思广益,仅供学习,侵权即删!!
  • 相关阅读:
    json解析:[1]gson解析json
    android 调用系统相机拍照 获取原图
    EventBus使用详解(二)——EventBus使用进阶
    java中的正则表达式
    java的UI设计--------------------------------待补充
    java的网络编程
    IO知识点整理(序列化,管道流,数据流,字节数组流,与编码)
    IO知识点整理(文件File类的使用)
    040 DataFrame中的write与read编程
    039 DataFrame的理解
  • 原文地址:https://www.cnblogs.com/hudunyu/p/14779633.html
Copyright © 2011-2022 走看看