echarts问题记录

Posted yyumeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了echarts问题记录相关的知识,希望对你有一定的参考价值。

 

下面是横向的柱状图:

option = {
  backgroundColor:‘#fff‘,
  tooltip: {
    trigger: ‘item‘,
    axisPointer: { // 坐标轴指示器,坐标轴触发有效
      type: ‘shadow‘ // 默认为直线,可选为:‘line‘ | ‘shadow‘
    },
    padding: 10,
    formatter: function(params) {
      return params.name + ‘</br>‘ + title+‘:‘ + params.value + ‘</br>‘ + ‘数据占比:‘ + params.data.rate+"%"
    }
  },
  yAxis : [
    {
      type : ‘category‘,
      data: res.datas.data[keyName],
      name: reportType=="area"?"省份":"机型",
    }
  ],
  xAxis : [
    {
      type : ‘value‘,
    axisLine:{
      show:true,
      lineStyle:{
        color:‘#DDDDDD‘,
        width:1
      }
    },
    splitLine:{
      show:false
    },
    axisLabel:{
      show:true,
      textStyle:{
        color:‘#000‘
      }
    }
   }
  ],
series: [{
  type: ‘bar‘,
  data:[{

    value:12,

    rate:1

    },{

    value:13,

    rate:2

    }]
  }],
label:{
  normal:{
      show:true,
      position:‘right‘,
      textStyle:{
        color:‘black‘
      },
      formatter:function(params){
          return params.value+","+params.data.rate+"%";

       }
    }
  }
};

 

 

其中

label:{
  normal:{
    show:true,
    position:‘top‘,
    textStyle:{
      color:‘black‘
    },

    formatter:function(params){
      return params.value+","+params.data.rate+"%";

    }
  }

}

使得柱状图上方可以显示数值,formatter里面是组合要显示的内容组合。

 

xAxis : [
{
type : ‘value‘,
axisLine:{
show:true,
lineStyle:{
color:‘#DDDDDD‘,
width:1
}
},
splitLine:{
show:false
},
axisLabel:{
show:true,
textStyle:{
color:‘#000‘
}
}
}
],

这个里面的type:value中的value 不能变化。而且series中的data数组中的每一项都要有value字段。不然图表不生效。需要查看echart配置了解一下。

以上是关于echarts问题记录的主要内容,如果未能解决你的问题,请参考以下文章

echarts问题记录

echarts使用的一些基本问题——记录一下

echarts使用记录翻页,事件

记录Echarts 常用配置

使用echart的雷达图的时候,如果文字越界的解决办法记录,标签文字自动换行

记录一次echarts4升级到echart5