echarts 日历项目整理

 

我的 echarts 

//公用样式定义
var cw = document.body.clientHeight / 70;
var textStyle = {
    fontSize: cw,
    color: "#c1f0fe",
}
var axisLabel = {
    show: true,
    textStyle: {
        fontSize: cw,
        color: "#c1f0fe"
    }
}
var axisLine = {
    lineStyle: {
        color: "#253769",
    }
}
var lineStyle = {
    color: "#253769",
}

    // 上报分部情况的 echares
    function shangBaoEcharts(obj) {
        var shangbao = document.getElementById('shangbao');
        var shangbaoChart = echarts.init(shangbao);
        var option;

        option = {
            color: ['#00a9f0', '#d08211', '#95004a'],
            legend: {   // 图例 legend
                data: ['无效问题', '重点问题', '环境问题'],
                right: '2%',
                top: '2%',
                itemWidth: 2,
                itemHeight: 12,
                textStyle: {
                    fontSize: cw,
                    color: '#d4edf9'
                },
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器,坐标轴触发有效
                    type: 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                }
            },
            xAxis: {
                name: '区县',
                nameTextStyle: {//y轴上方单位的颜色
                    color: '#c1f0fe'
                },
                axisLine: axisLine,
                axisTick: {
                    show: true,
                    inside: true
                },
                splitLine: {
                    show: false
                },
                axisLabel: {
                    interval: 0,
                    textStyle: {
                        fontSize: cw,
                        color: "#a8b8dd"
                    },
                    formatter: function (value) {
                        var ret = "";//拼接加\n返回的类目项
                        var maxLength = 2;//每项显示文字个数
                        var valLength = value.length;//X轴类目项的文字个数
                        var rowN = Math.ceil(valLength / maxLength); //类目项需要换行的行数
                        if (rowN > 3)//如果类目项的文字大于3,
                        {
                            for (var i = 0; i < rowN; i++) {
                                var temp = "";//每次截取的字符串
                                var start = i * maxLength;//开始截取的位置
                                var end = start + maxLength;//结束截取的位置
                                //这里也可以加一个是否是最后一行的判断,但是不加也没有影响,那就不加吧
                                temp = value.substring(start, end) + "\n";
                                ret += temp; //凭借最终的字符串
                            }
                            return ret;
                        }
                        else {
                            return value.split("").join("\n");
                        }
                    }
                },
                data: obj.cityArr
            },
            yAxis: {
                name: '数量(个)',
                nameTextStyle: {//y轴上方单位的颜色
                    color: '#c1f0fe'
                },
                axisTick: { //y轴刻度线
                    show: false
                },
                splitLine: {
                    show: false
                },
                type: 'value',
                axisLabel: axisLabel,
                axisLine: axisLine,
                minInterval: 1//只显示整数
            },
            grid: {
                left: '10%',
                right: '12%',
                bottom: 0,
                top: '20%',
                containLabel: true
            },
            series: [
                {
                    name: '无效问题',
                    type: 'bar',
                    stack: '1',
                    barWidth: 10,
                    data: obj.wuXiaoArr,
                    barWidth: 10,
                },
                {
                    name: '重点问题',
                    type: 'bar',
                    stack: '1',
                    barWidth: 10,
                    data: obj.zhongDianArr
                },
                {
                    name: '环境问题',
                    type: 'bar',
                    barWidth: 10,
                    stack: '1',
                    data: obj.huanJingArr
                }
            ]
        };
        option && shangbaoChart.setOption(option);
    }

别人的项目的日历

 

var option = {
        tooltip: {
            position: "top",
        },

        visualMap: {
            min: 0,
            max: 350,
            type: "piecewise",
            orient: "horizontal",
            // x: "right",
            right: "3%",
            y: "bottom",
            textStyle: {
                color: "#fff",
            },
            pieces: [
                { min: 300, label: "严重污染", color: "#a61134" }, // 不指定 max,表示 max 为无限大(Infinity)。
                { min: 201, max: 300, label: "重度污染", color: "#c13a78" },
                { min: 151, max: 200, label: "中度污染", color: "#bf2f25" },
                { min: 101, max: 150, label: "轻度污染", color: "#c35d1f" },
                { min: 51, max: 100, label: "良", color: "#a5a249" },
                { min: 0, max: 50, label: "优", color: "#6fc190" }, // 不指定 min,表示 min 为无限大(-Infinity)。
            ],
        },
        calendar: [
            {
                orient: "vertical",
                yearLabel: {
                    show: false,
                },
                dayLabel: {
                    firstDay: 1,
                    color: "#afd9ff",
                    nameMap: ["日", "一", "二", "三", "四", "五", "六"],
                    lineHeight:3*cw,
                    padding:0,
                    margin:0,
                    fontSize:1.2*cw,
                },
                monthLabel: {
                    show: false,
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: "red",
                        width: 0,
                        type: "solid",
                    },
                },
                itemStyle: {
                    normal: {
                        color:"rgba(1,38,133,0.15)",
                        borderWidth: 1,
                        borderColor: "rgb(3,44,84)",
                    },
                },
                top:"14%",
                left: "3%",
                right: "3%",
                bottom: "12%",
                cellSize: "auto",
                range: "", // 格式:yyyy-MM
            },
        ],
        series: [
            {
                type: "heatmap",
                coordinateSystem: "calendar",
                calendarIndex: 0,
                label: {
                    show: true,
                    formatter: function (params) {
                        var d = echarts.number.parseDate(params.value[0]);
                        return "{n|" + d.getDate() + "}   {v|" + params.value[1] + "}";
                    },
                    rich: {
                        n: {
                            fontSize: 12,
                        },
                        v: {
                            fontSize: 16,
                            fontWeight: "bold",
                        },
                    },
                },
                tooltip: {
                    formatter: function (params) {
                        const day = echarts.number.parseDate(params.value[0]).getDate();

                        return (
                            `${day}日<br />` +
                            params.marker +
                            "AQI: " +
                            params.value[1].toFixed(2)
                        );
                    },
                },
                data: [],
            },
        ],
    };

 邯郸项目的 日历

function pollution_calendar (){

    var cw = document.body.clientHeight / 70;
    var textStyle = {
        color: "#fff",
        fontSize: "12px",
    };
    var axisLabel = {
        show: true,
        textStyle: {
            color: "#fff",
        },
    };
    var axisLine = {
        lineStyle: {
            color: "rgba(112,145,127,0)", //左边线的颜色
        },
    };

    var myChart = echarts.init(document.getElementById("pollution_calendar"));
    var dateList = [
        ['2017-3-1', '100'],
        ['2017-3-2', '200'],
        ['2017-3-3', '300'],
        ['2017-3-4', '400'],
        ['2017-3-5', '500',],
        ['2017-3-6', '100'],
        ['2017-3-7', '200'],
        ['2017-3-8', '300'],
        ['2017-3-9', '400'],
        ['2017-3-10', '500'],
        ['2017-3-11', '100'],
        ['2017-3-12', '200'],
        ['2017-3-13', '300'],
        ['2017-3-14', '400'],
        ['2017-3-15', '5'],
        ['2017-3-16', '6'],
        ['2017-3-17', '7'],
        ['2017-3-18', '8'],
        ['2017-3-19', '9'],
        ['2017-3-20', '10',],
        ['2017-3-21', '1'],
        ['2017-3-22', '3'],
        ['2017-3-23', '2'],
        ['2017-3-24', '4'],
        ['2017-3-25', '5'],
        ['2017-3-26', '6'],
        ['2017-3-27', '7'],
        ['2017-3-28', '9'],
        ['2017-3-29', '8'],
        ['2017-3-30', '10'],
        ['2017-3-31', '12'],
    ];

    var heatmapData = [];
    var lunarData = [];
    for (var i = 0; i < dateList.length; i++) {
        heatmapData.push([
            dateList[i][0],
            Math.random() * 300
        ]);
        lunarData.push([
            dateList[i][0],
            dateList[i][1],
        ]);
    }

    console.log(lunarData, 'lunarData = [];')

    var option = {
        tooltip: {
            position: "top",
            formatter: function (params) {
                // return '降雨量: ' + params.value[1].toFixed(2);
                // var Xindex = params.value[0];  // 获取时间
                var time = '<span>时间:</spa>' + params.value[0] + '<br/>'
                var data = params.marker +  Number(params.value[1])
                return time + data
            }
        },

        visualMap: {
            show: false,
            min: 0,
            max: 350,
            type: "piecewise",
            orient: "horizontal",
            // x: "right",
            right: "3%",
            y: "bottom",
            calculable: true,
            // seriesIndex: [2],
            left: 'center',
            bottom: 20,
            pieces: [
                { min: 300, label: "严重污染", color: "#a61134" }, // 不指定 max,表示 max 为无限大(Infinity)。
                { min: 201, max: 300, label: "重度污染", color: "#c13a78" },
                { min: 151, max: 200, label: "中度污染", color: "#bf2f25" },
                { min: 101, max: 150, label: "轻度污染", color: "#c35d1f" },
                { min: 51, max: 100, label: "良", color: "#a5a249" },
                { min: 0, max: 50, label: "优", color: "#6fc190" }, // 不指定 min,表示 min 为无限大(-Infinity)。
            ],
            // inRange: {
            //     color: ['#e0ffff', '#006edd'],
            //     opacity: 0.3
            // },
            // controller: {
            //     inRange: {
            //         opacity: 0.5
            //     }
            // }
        },

        calendar: [{
            top: "10%",
            left: "4%",
            right: "4%",
            bottom: "1%",
            cellSize: "auto",
            yearLabel: {show: false},
            orient: 'vertical',
            dayLabel: {
                firstDay: 1, // 一周从周几开始,默认从周日开始
                color: "#afd9ff",
                nameMap: ["日", "一", "二", "三", "四", "五", "六"],
                fontSize:1.2*cw,
                padding:0,
                margin:0,
                lineHeight:3*cw,
            },
            monthLabel: {
                show: false
            },
            range: '2017-03'
        }],

        series: [
            {
                type: 'heatmap',
                // name: '降雨量',
                coordinateSystem: 'calendar',
                // symbolSize: 1,
                label: {
                    show: true,
                    formatter: function (params) {
                        // console.log(params.value, 'params')
                        var d = echarts.number.parseDate(params.value[0]);
                        // return d.getDate() + '\n\n' + params.value[2] + '\n\n';
                        return d.getDate();
                    },
                    color: '#fff',
                    fontSize:1.2*cw,
                    fontFamily: 'Furore'
                    // rich: {
                    //     n: {
                    //         fontSize: 12,
                    //     },
                    //     v: {
                    //         fontSize: 14,
                    //         fontFamily: "Furore",
                    //     },
                    // },
                },
                data: lunarData
            },
            // {
            //     type: 'scatter',
            //     coordinateSystem: 'calendar',
            //     symbolSize: 1,
            //     label: {
            //         show: true,
            //         formatter: function (params) {
            //             return '\n\n\n' + (params.value[3] || '');
            //         },
            //         fontSize: 14,
            //         fontWeight: 700,
            //         color: '#a00'
            //     },
            //     data: lunarData
            // },
            // {
            //     name: '降雨量',
            //     type: 'heatmap',
            //     coordinateSystem: 'calendar',
            //     data: heatmapData
            // }
         ]
    };

    option && myChart.setOption(option);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值