Echarts 實現(xiàn)象形柱圖(三角柱子)

先來看下實現(xiàn)效果:



代碼:(vue+typescript+Echarts)

HTML部分:

<div class="echarts" ref="box"></div>

TS部分:

public mounted() {
    this.drawBarEcharts();
  }
  public drawBarEcharts() {
    const chart = echarts.init(this.$refs.box as HTMLDivElement);
    const option: any = {
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'none',
        },
        formatter: (params: any) => {
          return params[0].name + ': ' + params[0].value;
        },
      },
      xAxis: {
        data: ['類型1', '類型2', '類型3'],
        axisTick: { show: false },
        axisLine: { show: false },
        axisLabel: {
          textStyle: {
            color: '#fff',
          },
        },
      },
      yAxis: {
        splitLine: { show: false },
        axisTick: { show: false },
        axisLine: { show: false },
        axisLabel: { show: false },
      },
      // 設(shè)置每個三角柱子不同的顏色
      color: (params: any) => {
        const colorList = ['#FDB628', '#67E0E3', '#249CF9'];
        return colorList[params.dataIndex];
      },
      series: [
        {
          name: 'hill',
          type: 'pictorialBar',
          // barCategoryGap: 同一系列的柱間距離,默認(rèn)為類目間距的20%,可設(shè)固定值
          barCategoryGap: '-100%',
          symbol: 'path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z',
          itemStyle: {
            // 每根柱子的透明度為 0.7
            normal: {
              opacity: 0.7,
            },
            // 鼠標(biāo)移入柱子上 透明度變?yōu)?1
            emphasis: {
              opacity: 1,
            },
          },
          data: [15, 18, 12],
          z: 10,
          label: {
            normal: {
              // 設(shè)置每根柱子上字的位置和顏色
              show: true,
              position: 'top',
              color: '#fff',
            },
          },
        },
      ],
    };
    chart.setOption(option);
  }

CSS部分:

.echarts {
  width: 600px;
  height: 500px;
  margin: 0 auto;
  background: rgba(26, 128, 137, 0.7);
  border: 2px solid rgba(0, 107, 108, 0.7);
  box-shadow: inset 0px -8px 57px 0px rgba(20, 196, 164, 0.7);
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

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