vue3+ts+echarts饼图,封装的饼图组件,每次调用的时候颜色不重复?

封装一个echarts的饼图组件,如何让每次调用的时候颜色不重复,封装echats饼图组件我会,如何让颜色不重复怎么解决?
有思路也可以

阅读 1.9k
1 个回答

方案1:
随机生成颜色:

function getColor(){
                var color = "#";
                //一个十六进制的值的数组
                var array = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];
                //得到6个随机数
                for (var i = 0; i < 6; i++) {
                    var num = parseInt(Math.random()*16);
                    color += array[num];
                }
                return color;
            }

方案二:
多下载几套主题:
image.png

https://echarts.apache.org/zh/theme-builder.html
推荐问题
logo
Microsoft
子站问答
访问
宣传栏