echarts練習(xí)一:柱狀圖

效果圖.jpg
<template>
  <div>
    <div id="echarts" style="width: 200px; height: 200px"></div>
  </div>
</template>

<script>
export default {
  name: "SzCityMobileMianIndex",

  data() {
    return {
      myCharts: null,
    };
  },

  mounted() {
    this.myCharts = this.$echarts.init(document.getElementById("echarts"));
    this.initView();
  },

  methods: {
    initView() {
      let option1 = {
        // 設(shè)置標(biāo)題
        title: {
          text: "獲獎(jiǎng)狀況",
        },
        //
        toolTip: {
          trigger: "none",
        },
        // 設(shè)置網(wǎng)格的區(qū)域
        grid: {
          left: "20%",
          top: "20%",
          right: "10%",
          bottom: "30%",
          // 是否包含刻度
          containLabel: false,
        },
        // x軸設(shè)置
        xAxis: {
          // type為值
          type: "value",
          // X軸標(biāo)簽
          axisLabel: {
            show: false,
          },
          // x軸的細(xì)線是否顯示
          axisLine: {
            show: false,
          },
          // x軸的刻度線是否顯示
          axisTick: {
            show: false,
          },
          // 分割線是否顯示
          splitLine: {
            show: false,
          },
        },
        yAxis: [
          {
            type: "category",
            data: ["區(qū)級(jí)", "市級(jí)", "國(guó)家級(jí)"],
            axisLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
          },
          {
            type: "category",
            axisLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            data: [10, 20, 30],
          },
        ],
        series: [
          {
            name: "下",
            type: "bar",
            data: [30, 30, 30],
            yAxisIndex: 1,
            // 關(guān)閉鼠標(biāo)hover時(shí)高亮效果
            emphasis: {
              disabled: true,
              focus: "none",
            },
            // 柱子寬度
            barWidth: 15,
            itemStyle: {
              // 柱子的圓角
              borderRadius: 7.5,
              // 設(shè)置顏色
              color: () => {
                return {
                  type: "linear",
                  x: 1,
                  y: 0,
                  x2: 0,
                  y2: 0,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#4E5969", // 0% 處的顏色
                    },
                    {
                      offset: 1,
                      color: "#272C36", // 100% 處的顏色
                    },
                  ],
                  global: false, // 缺省為 false
                };
              },
            },
          },
          {
            name: "上",
            type: "bar",
            barWidth: 15,
            itemStyle: {
              borderRadius: 7.5,
              color: (params) => {
                var colorList = [
                  ["#272C36", "#57A9FB"],
                  ["#272C36", "#ED6A0C"],
                  ["#272C36", "#F1924E"],
                ];

                var colorItem = colorList[params.dataIndex];
                return {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 1,
                  y2: 0,
                  colorStops: [
                    {
                      offset: 0,
                      color: colorItem[0], // 0% 處的顏色
                    },
                    {
                      offset: 1,
                      color: colorItem[1], // 100% 處的顏色
                    },
                  ],
                  global: false, // 缺省為 false
                };
              },
            },
            data: [12, 18, 25],
            yAxisIndex: 0,
            label: {
              show: true,
              position: "insideTopRight",
              offset: [0, -20],
              color: "#F1924E",
              formatter: (params) => {
                switch (params.dataIndex) {
                  case 0:
                    return params.data / 3;
                    break;
                  case 1:
                    return params.data / 1.5;
                    break;
                  case 2:
                    return params.data;
                    break;
                }
              },
            },
          },
        ],
      };
      this.myCharts.setOption(option1);
    },
  },
};
</script>

<style scoped>
</style>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容