/*
 * @Author: your name
 * @Date: 2021-10-15 15:15:27
 * @LastEditTime: 2021-11-11 16:05:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /data-show/src/views/BrandComparison/channelDistribution/opt.js
 */
import { bigNumberTransform } from "@/utils/gol/dataTool"
import * as echarts from "echarts";
let colors = [new echarts.graphic.LinearGradient(0, 0, 0, 1, [
    {
        offset: 0,
        color: '#3373CC'
    },
    {
        offset: 1,
        color: '#071a32'
    }
], false), new echarts.graphic.LinearGradient(0, 0, 0, 1, [
    {
        offset: 0,
        color: '#63AECC'
    },
    {
        offset: 1,
        color: '#071a32'
    }
], false), new echarts.graphic.LinearGradient(0, 0, 0, 1, [
    {
        offset: 0,
        color: '#54BF93'
    },
    {
        offset: 1,
        color: '#071a32'
    }
], false), new echarts.graphic.LinearGradient(0, 0, 0, 1, [
    {
        offset: 0,
        color: '#CC9D12'
    },
    {
        offset: 1,
        color: '#071a32'
    }
], false), new echarts.graphic.LinearGradient(0, 0, 0, 1, [
    {
        offset: 0,
        color: '#CC7733'
    },
    {
        offset: 1,
        color: '#071a32'
    }
], false), new echarts.graphic.LinearGradient(0, 0, 0, 1, [
    {
        offset: 0,
        color: '#CC5B41'
    },
    {
        offset: 1,
        color: '#071a32'
    }
], false)]
function createData(dataList = [], dx=[]) {
    /*series: [
        {
            name: '奥迪',
            type: 'bar',
            barGap: 0,
            barWidth: 16,
            emphasis: {
                focus: 'series'
            },
            data: [320, 332, 301, 334, 390, 400]
        },*/
    let arr = [];
    dataList.forEach(e => {
        let a = [];
        let Data = e.Data || {};
        dx.forEach(e => {
            a.push(Data[e])
        })
        let o = {
            name: e.Name,
            type: 'bar',
            barWidth: 16,
            barGap: '9%',
            emphasis: {
                focus: 'series'
            },
            data: a
        };
        arr.push(o)
    })
    return arr;
}
export default function createOpt(dataList = [],dx = []) {
    let info = createData(dataList, dx);
    return {
        grid: {
            top: 56,
            left: 10,
            right: "5%",
            bottom: 10,
            containLabel: true,
        },
        color: colors,
        legend: {
            textStyle: { //图例文字的样式
                color: '#fff',
                fontSize: 10
            },
            y: 12,
            x: 16,
            itemWidth: 12,
            itemHeight: 12
        },
        tooltip: {
            trigger: "axis",
            backgroundColor: "#08182F",
            color: "#fff",
            borderColor: "#3373CC",
            textStyle: {
                color: "#fff", //设置文字颜色
            },
            extraCssText: "box-shadow: 0px 0px 10px 0px #3373CC;",
        },
        xAxis: [
            {
                type: 'category',
                axisTick: {
                    show: false,
                },
                axisLine: {
                    show: false,
                    lineStyle: {
                        color: "#fff",
                    },
                },
                data: dx
            }
        ],
        yAxis: [
            {
                type: 'value',
                axisLine: {
                    show: false,
                    lineStyle: {
                        color: "#FFF",
                    },
                },
                axisLabel: {
                    formatter: (value) => {
                      let str = bigNumberTransform(value);
                      return str;
                    }
                },
                splitLine: {
                    lineStyle: {
                        type: "dashed", // y轴分割线类型
                        color: "#012b4b",
                    },
                },
            }
        ],
        series: info
    }
}