Echarts中dataZoom动态赋值参数

    Echarts官网参考

Examples - Apache EChartsECharts, a powerful, interactive charting and visualization library for browserhttps://echarts.apache.org/examples/zh/editor.html?c=bar-large案例:

dataZoom动态赋值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #air_echarts_container{
            width: 500px;
            height: 500px;
        }
    </style>
</head>

<body>
    <div id="air_echarts_container"></div>
</body>
// 需要引入echarts.min.js加载图表
<script src="./js/echarts.min.js"></script>
<script src="./js/jquery.min.js"></script>
<script>
    $(function(){
        showTargetAirContrast('air_echarts_container','传入的数据');
    })
     function showTargetAirContrast(id, data) {
        var chartDom = document.getElementById(id);
        chart = echarts.init(chartDom);
        let xTime = [];
        for (let i = 0; i < data.length; i++) {
            xTime.push(data[i].name)
        }
        /* 
            1.先获取到后端返回的数据个数
            2. 判断数据的个数
               2.1. 大于20(长度可以根据项目而定) 就只显示后面两个数据
               2.2.  否则显示全部数据
         */
        var startValue, endValue;
        if (xTime.length >= 20) {
            startValue = xTime.length - 2 * 10;//数据窗口范围的起始数值
            endValue = xTime.length - 1 * 10;
        } else {
            startValue = 0
            endValue = 100
        }
        var fontColor = '#fff';
        var option = {
            backgroundColor: 'rgba(255, 255, 255, 0)',
            tooltip: {
                trigger: 'axis'
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '13%',
                containLabel: true
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                axisLabel: {
                    color: '#fff',
                    fontSize: '2rem',
                    padding: [5, 0, 0, 0]
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: 'rgba(255, 255, 255, 1)'
                    }
                },
                axisTick: {
                    show: false,
                },
                splitLine: {
                    show: false,
                    lineStyle: {
                        color: 'rgba(255, 255, 255, 1)'
                    }
                },
                data: xTime
            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    formatter: '{value}',
                    textStyle: {
                        color: '#fff',
                        fontSize: '2rem'
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: '#fff'
                    }
                },
                axisTick: {
                    show: false,
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: 'rgba(255, 255, 255, 1)'
                    }
                }
            },
            dataZoom: [
                {
                    type: 'inside',
                    //start:0,
                    //end:30,
                    startValue: startValue,                           //数据窗口范围的起始数值
                    endValue: endValue
                },
                {
                    height: 12,
                    textStyle: {
                        color: "#fff",
                    }
                }
            ],
            series: [
                {
                    name: 'name',
                    type: 'line',
                    showSymbol: true,
                    color: "#FF0404",     //设定实线点的颜色
                    symbol: 'circle',     //设定为实心点
                    symbolSize: 20,   //设定实心点的大小
                    lineStyle: {
                        normal: {
                            width: 2,
                            color: "#FF0404", //设置实线的颜色
                        },
                    }
                }
            ]
        };
        chart.setOption(option);
        chart.on('datazoom', function (params) {
            listLoad = false
            if (params.end == 100) {
                listLoad = true
            }
        })
    }
</script>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值