echarts不同柱状渐变色

/**
 * 按天统计公交载客量
 */
import React, { Component } from 'react'
import ReactEcharts from 'echarts-for-react'
import echarts from 'echarts'

import './index.less'

export default class BusLoad extends Component {
  constructor (props) {
    super(props)

    this.state = {
      chartsData: []
    }
  }

  createOptions = (chartsData = []) => {
    let padding = chartsData.length && chartsData[0].length? [0, 0, 0, 90]: [0, 0, 0, 30]
    const myOptions = {
      tooltip: {
        trigger: 'axis'
      },
      grid: {
        left: '0%',
        right: '0%',
        bottom: '3%',
        top: '20%',
        containLabel: true
      },
      xAxis: {
        type: 'category',
        axisLabel: {
          color: '#9B9B9B'
        },
        splitLine: {
          show: false
        },
        data: [1,2,3,4,5]
      },
      yAxis: [{
        name: '发送人次',
        nameTextStyle: {
          color: '#AFBCC4',
          padding: padding
        },
        type: 'value',
        axisTick: {
          show: false
        },
        splitLine: {
          show: false
        },
        axisLine: {
          show: false
        },
        axisLabel: {
          color: '#9B9B9B'
        }
      }],
      series: [{
        name: '载客量',
        type: 'bar',
        yAxisIndex: 0,
        barWidth : 20,
        barMaxWidth: 40,
        itemStyle: {
            normal:{
         //每个柱子的颜色即为colorList数组里的每一项,如果柱子数目多于colorList的长度,则柱子颜色循环使用该数组
              color: function (params){
                 var colorList = [
                  ['#E02020','rgba(224,32,32,0.10)'],
                  ['#FA6400','rgba(250,133,0,0.10)'],
                  ['#F8E71C ','rgba(248,231,28,0.10)'],
                 ['#00C1DE','rgba(0,193,222,0.10)'],
                  ['#6236FF','rgba(98,54,255,0.10)']];
                 
                                              var index=params.dataIndex;
                                              if(params.dataIndex >= colorList.length){
                                                      index=params.dataIndex-colorList.length;
                                               }
                 
                                  return new echarts.graphic.LinearGradient(0, 0, 0, 1,
                                  [
                                     {offset: 0, color: colorList[index][0]},
                                     {offset: 1, color: colorList[index][1]}
                                  ]);
                          },
                          barBorderRadius: 5  //柱状角成椭圆形
                        },
        },
        label: {
          show: false
        },
        data: [5,6,3,1,2]
      }]
    }
    return myOptions
  }

  componentWillReceiveProps (nextProps) {
    this.setState({ chartsData: nextProps.data })
  }

  render () {
    const myOptions = this.createOptions(this.state.chartsData)

    return (
      
) } }

你可能感兴趣的:(echarts不同柱状渐变色)