echartJs.js 2.67 KB
function getEchartOption(title, threeContext, xData, costData, numData, ratio, topCostData, topNumData, topRatio){

    var colors = ['#5793f3', '#d14a61', '#675bba'];

    var option = {
        title:{
            text:title
        },
        color: colors,
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross'
            }
        },

        grid: {
            right: '20%'
        },
        toolbox: {
            feature: {
                dataView: {show: true, readOnly: false},
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },
        legend: {
            data:threeContext
        },
        xAxis: [
            {
                type: 'category',
                axisTick: {
                    alignWithLabel: true
                },
                data: xData
            }
        ],
        yAxis: [
            {
                type: 'value',
                name: threeContext[1],
                min: 0,
                max: topNumData*1.2,
                position: 'right',
                axisLine: {
                    lineStyle: {
                        color: colors[0]
                    }
                },
                axisLabel: {
                    formatter: '{value} '
                }
            },
            {
                type: 'value',
                name: threeContext[0],
                min: 0,
                max: topCostData*1.2,
                position: 'right',
                offset: 80,
                axisLine: {
                    lineStyle: {
                        color: colors[1]
                    }
                },
                axisLabel: {
                    formatter: '{value} '
                }
            },
            {
                type: 'value',
                name: threeContext[2],
                min: 0,
                max: topRatio*1.2,
                position: 'left',
                axisLine: {
                    lineStyle: {
                        color: colors[2]
                    }
                },
                axisLabel: {
                    formatter: '{value}'
                }
            }
        ],
        series: [
            {
                name:threeContext[1],
                type:'bar',
                data:numData
            },
            {
                name:threeContext[0],
                type:'bar',
                yAxisIndex: 1,
                data:costData
            },
            {
                name:threeContext[2],
                type:'line',
                yAxisIndex: 2,
                data:ratio
            }
        ]
    };


    return option;
}