vue项目中echarts渐变色设置

主要代码

normal: {
                                    color: function(params) {
                                     var colorList = [
                                    {
                                        c1: ' #fce5ca',  //管理
                                        c2: '#FF9D62'                                                                   
                                    },
                                    {
                                        c1: ' #508DFF',  //实践
                                        c2: '#26C5FE'
                                    },
                                    {
                                        c1: '#63E587',//操作
                                        c2: '#5FE2E4'
                                    }]
                                     return new that.$echarts.graphic.LinearGradient(1, 0, 0, 0, [{ //颜色渐变函数 前四个参数分别表示四个位置依次为左、下、右、上

                                            offset: 0,
                                            color: colorList[params.dataIndex].c1
                                        }, {
                                            offset: 1,
                                            color: colorList[params.dataIndex].c2
                                        }])                                    
                                      
                                    }
                                }

完整代码

<template>
  <div>
    <div id="myChart" :style="{width: '200px', height: '3200px'}"></div>
  </div>
</template>
<script>
import Vue from "vue";
export default {
  name: "component",
  data() {
    return {};
  },

  mounted() {
    this.drawChart();
  },

  methods: {
//图表
    drawChart() {
    let that=this;
      // 基于准备好的dom,初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById("myChart"));
      // 绘制图表
      myChart.setOption({
        title: {},
        series: [
          {
            name: "demo",
            type: "pie",
            radius: "55%",
            center: ["40%", "50%"],
            data: [
            { value: 1, name: "苹果" },
            { value:2, name: "香蕉" },
            { value: 3, name: "橘子" }
          ],

            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)"
              },

              normal: {
                color: function(params) {
                 //渐变色列表,自定义自己需要的颜色
                  var colorList = [    
                    {
                      c1: "#5eae72", 
                      c2: "#5391f1"
                    }, {
                      c1: " #f00", 
                      c2: "#fff"
                    },{
                      c1: "#fea10f", 
                      c2: "#fa8013"
                    }
                  ];

                  return new that.$echarts.graphic.LinearGradient(1, 0, 0, 0, [
                    {
                      //颜色渐变函数 前四个参数分别表示四个位置依次为左、下、右、上
                      offset: 0,
                      color: colorList[params.dataIndex].c1
                    },{
                      offset: 1,
                      color: colorList[params.dataIndex].c2
                    }
                  ]); 
                }
              }
            }
          }
        ]
      });
    }
  }
};

</script>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值