当前位置:网站首页>Echerts add pie chart random color

Echerts add pie chart random color

2022-04-23 21:25:00 Sister Chunfeng

 Insert picture description here


option = {
    
  
  xAxis: {
    
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  },
  yAxis: {
    
    type: 'value'
  },
  series: [
    {
    
      data: [
        120,
        200,
        150,
        80,
        70,
        110,
        130
      ],
      //  Random color 
      // itemStyle: {
    
      // normal: {
    
      // color:function(){return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);}
      // },
      // },
      //  Assign colors 
      itemStyle: {
    
	      normal: {
    
        	color: function(params) {
    
        	var colorarrays = ['#0769CB', '#00ABBD', '#ffd886', "#9F2E61", "#4D670C",'#0769CB', '#00ABBD'];
        	return colorarrays[params.dataIndex];
        	}
        }
              
      },
      type: 'bar'
    }
  ]
};

版权声明
本文为[Sister Chunfeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/110/202204200620163682.html