ionic集成echart展示条形图

npm i echarts

html中定义如下:

<section>
  <div echarts [options]="chartOption" class="bar-chart"></div>
</section>

ts文件处理:

import { Component, OnInit, Input } from "@angular/core";

@Component({
  selector: "app-customer-source",
  templateUrl: "./customer-source.component.html",
  styleUrls: ["./customer-source.component.scss"]
})
export class CustomerSourceComponent implements OnInit {
  @Input() tagData: any;

  chartOption: any; // 条形图数据
  appTypeCustom: any;
  constructor() {
  }

  ngOnInit() {
    const timer = setTimeout(() => {
      this.chartOption = {
        grid: {
          left: 0,
          right: 0,
          bottom: 0,
          top: 0
        },
        xAxis: {
          type: "value",
          show: false,
          max: this.tagData.data.data[0].maxValue
          // boundaryGap: [0, 0]
        },
        yAxis: {
          type: "category",
          show: false
        },
        series: [
          {
            type: "bar", // 类型条形图
            barCategoryGap: 90, // 条形图之间的间距
            z: 0,
            barWidth: 8, 
            barGap: "-100%",
            data: this.tagData.data.data.map(v => v.maxValue),
            itemStyle: {
              normal: {
                color: this.appTypeCustom !== 'LJ' ? "#FFEFE3" : "#FFF8E6", // 条形图底色
                barBorderRadius: 8
              }
            },
            label: {
              normal: {
                show: true,
                align: "right",
                textStyle: {
                  color: this.appTypeCustom !== 'LJ' ? "#27282E" : "#252629",
                  fontSize: 16,
                  // fontFamily: "PingFangSC-Semibold,PingFangSC",字体去掉
                  fontWeight: 600
                },
                position: ["98%", -25],
                formatter: data => {
                  return this.tagData.data.data[data.dataIndex].numLabel;
                }
              }
            }
          },
          {
            type: "bar",
            barCategoryGap: 90,
            z: 1,
            barWidth: 8,
            data: this.tagData.data.data,
            itemStyle: {
              normal: {
                color: params => {
                  return {
                    x: 0,
                    y: 0,
                    x2: 1,
                    y2: 0,
                    colorStops: [
                      {
                        offset: 0,
                        color: this.appTypeCustom !== 'LJ' ? "#FF9500" : "#FFE14A" // 进度条当前进度颜色起始值
                      },
                      {
                        offset: 1,
                        color: this.appTypeCustom !== 'LJ' ? "#FF6314" : "#FFCA3A"
// 进度条当前进度颜色结束值
                      }
                    ]
                  };
                },
                barBorderRadius: 8
              }
            },
            label: {
              normal: {
                show: true,
                textStyle: {
                  color: this.appTypeCustom !== 'LJ' ? "#27282E" : "#252629",
                  fontSize: 16
                },
                position: [0, -25],
                formatter: data => {
                  let icon = "";
                  switch (data.data.icon) {
                    case "build":
                      icon = "{build| }" + "  ";
                      break;
                    case "school":
                      icon = "{school| }" + "  ";
                      break;
                    case "hospital":
                      icon = "{hospital| }" + "  ";
                      break;
                    case "metro":
                      icon = "{metro| }" + "  ";
                      break;
                    case "transit":
                      icon = "{transit| }" + "  ";
                      break;
                    case "village":
                      icon = "{village| }" + "  ";
                      break;
                    case "market":
                      icon = "{market| }" + "  ";
                      break;
                    default:
                      icon = "";
                      break;
                  }
                  return icon + data.data.title;
                },
                rich: {
                  build: {
                    height: 16,
                    width: 16,
                    backgroundColor: {
                      image: "../../../assets/icon/details_icon_build@2x.png"
                    }
                  },
                  school: {
                    height: 16,
                    width: 16,
                    backgroundColor: {
                      image: "../../../assets/icon/details_icon_school@2x.png"
                    }
                  },
                  hospital: {
                    height: 16,
                    width: 16,
                    backgroundColor: {
                      image: "../../../assets/icon/details_icon_hospital@2x.png"
                    }
                  },
                  metro: {
                    height: 16,
                    width: 16,
                    backgroundColor: {
                      image: "../../../assets/icon/details_icon_metro@2x.png"
                    }
                  },
                  transit: {
                    height: 16,
                    width: 16,
                    backgroundColor: {
                      image: "../../../assets/icon/details_icon_transit@2x.png"
                    }
                  },
                  village: {
                    height: 16,
                    width: 16,
                    backgroundColor: {
                      image: "../../../assets/icon/details_icon_village@2x.png"
                    }
                  },
                  market: {
                    height: 16,
                    width: 16,
                    backgroundColor: {
                      image: "../../../assets/icon/details_icon_market@2x.png"
                    }
                  }
                }
              }
            }
          }
        ]
      };
      clearTimeout(timer);
    }, 100);
  }

}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值