Angular4 echarts柱形图及柱形图上文字显示方向

html中

 <div echarts [options]="echartsOptions" id="barchart"></div>

在Angular4中的ts文件

import * as echarts from 'echarts';
import * as numeral from 'numeral';
@Component({
  selector: 'app-barchart',
  templateUrl: './barchart.component.html',
  styleUrls: ['./barchart.component.scss']
})
export class BarChartComponent implements OnInit {
barchart:any;
echartsOptions:any;
 ngOnInit() {
this.barchart = echarts.init(document.getElementById('barchart'));
 this.echartsOptions = {
      animation: false,
      title : {
        text: '',
        subtext: '',
        textStyle : {
          color : '#FFF' ,
          fontWeight: 'normal',
          fontFamily: 'globalFirstFont'
        },
        x: '25%',
        y: '-2%'
      },
      tooltip : {
        trigger: 'axis',
        axisPointer: {
          type: 'none'
        },
        //自定义tooltip显示的数据金钱符号及格式化
         formatter: function(datas) {
                let res = datas[0].name + '<br/>', val;
                for (let i = 0, length = datas.length; i < length; i++) {
                  val =  '€' + numeral(datas[i].value / 100).format('0,0.00');
                  res += datas[i].seriesName + ':' + '&nbsp;&nbsp;' + val + '<br/>';
                }
                return res;
              }
      },
      legend: {
        data:  ['収入', '支出'] ,
        show : false,
        textStyle : {
          color : '#FFF' ,
          fontSize : 16 ,
        },
        bottom: '0',
        // padding_top: 20
      },
      calculable : true,
      grid: {
        left: '3%',
        right: '3%',
        bottom: '15%',
        top: '8%',
        // containLabel: true
      },
      xAxis : [
        {
          scale: true,
          type : 'category',
          // splitNumber: 3,
          nameGap : 20,
          data : [1,2,3,4,5,6],
          color : '#FFF' ,
          fontSize : 18 ,
          axisTick: {
            show: false
          },
          axisLine : {
            show : false,
            lineStyle : {
              width: 3,
              type: 'solid',
              color: '#4073FF',
              alpha: .4
            }
          },
          splitLine: {
            show: false
          },
          axisLabel : {
            textStyle : {
              color : '#323232' ,
              fontSize : 16 ,
            }
          }
        }
      ],
      yAxis : [
        {
          type : 'value',
          show: false,
        }
      ],
      series : [
        {
          barGap : 1,
          name: 'title',
          type: 'bar',
        barWidth: 20,
          itemStyle: {
            emphasis: {
              barBorderRadius: [0, 30, 30, 0]
            },
            normal : {
              barBorderRadius: [4, 4, 4, 4],
              borderWidth: 1,
              borderColor: '#4073FF',
              **//自定义每个柱子的颜色**
              color: function(params) {
                const colorList = ['#FFF', '#FFF', '#FFF', '#FFF', '#FFF', '#FFC15D'];
                return colorList[params.dataIndex];
              },
              label : {
                show : true,
                textStyle : {
                  fontSize : 14,
                  color: '#4073FF',
                  fontFamily: 'globalFirstFont'
                },
                rotate: -90,
                align: 'left',
                verticalAlign: 'middle',
                position: 'insideTop',
                padding_top: 10,
              }
            },
          },
          data: [{value: 195000}, {value: 247250}, {value: 167500}, {value: 172250}, {value: 187000}, {value: 180000,
            label: {normal: {textStyle: {color: '#FFF'}}}, itemStyle: {  emphasis: { color: '#FFC15D' }, normal : {borderColor:'#FFF'}}
          }]
        },
        {
          barGap : 0.2,
          name:  '支出',
          type: 'bar',
         barWidth : 20,
          itemStyle: {
            emphasis: {
              barBorderRadius: [0, 30, 30, 0],

            },
            normal : {
              barBorderRadius: [4, 4, 4, 4],
              color: function(params) {
                const colorList = ['#4073FF', '#4073FF', '#4073FF', '#4073FF', '#4073FF', '#FF9400'];
                return colorList[params.dataIndex];
              },
              label : {
                show : true,
                textStyle : {
                  fontSize : 14,
                  color: '#FFF',
                  fontFamily: 'globalFirstFont'
                },
                //柱子文字垂直显示
                rotate: -90,
                align: 'left',
                verticalAlign: 'middle',
                position: 'insideTop',
                padding_top: 10,
                formatter: function (a) {
                  return   '€ ' + numeral(a.value / 100).format('0,0.00');
                },
              }
            },
          },
          data: [247250, 187000, 237000, 172250, 189500,
            {value: 95000,
              label: {itemStyle: {  emphasis: { color: '#FF9400' } , normal: {label: { padding_top: 10}}}}
            }]
        }
      ]
    };
    this.barchart.setOption(this.echartsOptions, true);
}



}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值