使用echarts 实现折线图

需求:使用echarts 实现折线图,右侧表格展示对应数据,可以修改数据,右侧输入框更改数据后刷新图表。效果如图:

 

主要代码如下:

    /*css*/
    .apGamma-td {
        text-align: center;
        line-height: 36px;
        width: 36px;
        height: 36px;
        background: rgb(85, 218, 206);
        border: 1px solid rgb(255, 255, 255);
        display: inline-table;
    }

    .apGamma-input {
        text-align: center;
        line-height: 36px;
        width: 90px;
        height: 36px;
        background: rgb(247, 240, 191);
        border: 1px solid rgb(255, 255, 255);
    }
    #apGammaEcharts {
        height:450px;
        border: 1px solid #a0a0a0;
    }
    #tableCont {
        height: 470px;
        overflow-y: auto;
        overflow-x: hidden;
    }

    <div class="layui-row layui-col-space20">
        <div class="layui-col-xs4">
            <form class="layui-form layui-form-pane" lay-filter="apGammaModal">
            </form>
        </div>
        <div class="layui-col-xs6">
            <div id="apGammaEcharts"></div>
        </div>
        <div class="layui-col-xs2" id="tableCont">
            <table id="apGammaTable">
            </table>
        </div>
    </div>
    


    //页面引入echarts插件
    <script src="js/libs/echarts.min.js"></script>
class GammaController {
    constructor() {
        this.R_Gamma = new TxGamma();
        this.echarts = echarts;
    }

    initialize() {
        this.initGammaLineChart();
        this.AddCustomGamma();
    }

    initGammaLineChart() {
        // 基于准备好的dom,初始化echarts实例
        this.myChart = this.echarts.init(document.getElementById('apGammaEcharts'));
        // 指定图表的配置项和数据
        var option = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    // type: 'cross'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                // data: [0, 64, 128, 192, 255]
                data: function () {
                    let list = [];
                    for (let i = 0; i <4096; i++) {
                        list.push(i);
                    }
                    return list;
                }(),
                axisLabel: {
                    interval: 1024,
                    showMaxLabel: true
                }
            },
            yAxis: {
                boundaryGap: false,
                // data: [0, 16384, 32768, 49152, 65536]
                // type: 'value',
                // axisPointer: {
                //     snap: true
                // },
                data: function () {
                    let list = [];
                    for (let i = 0; i <= 65536; i++) {
                        list.push(i);
                    }
                    return list;
                }(),
                axisLabel: {
                    interval: 16383,
                    showMaxLabel: true
                }
            },
            series: [{
                data: this.R_Gamma.gammaTableBC, //数据
                type: 'line',
                smooth: true,
                // symbol: 'none',
                color: ['blue']
            }
                // , {
                //     data: this.G_Gamma.gammaTableBC,
                //     type: 'line',
                //     smooth: true,
                //     color: ['green']
                // }, {
                //     data: this.B_Gamma.gammaTableBC,
                //     type: 'line',
                //     smooth: true,
                //     color: ['blue']
                // }
            ]
        };

        // 使用刚指定的配置项和数据显示图表。
        this.myChart.setOption(option);
    }

    AddCustomGamma() {
        let that = this;
        $("#apGammaTable").empty();
        for (let i = 0; i < 4096; i++) {
            let html = "<tr><td class='apGamma-td'>" + i + "</td><td><input type='text' class='apGamma-input numInput' id='GammaValue_" + i + "'></td></tr>";
            $("#apGammaTable").append(html);
        }
        $(".apGamma-input").on("change", function (e) {
            let id = e.currentTarget.id.replace(/[^0-9]/ig, "");
            let val = e.currentTarget.value;
            that.getCustomGammaData(id, val);
        });
        console.log(this.R_Gamma)
        that.updateCustGammaData();
    }

    getCustomGammaData(i, val) {
        this.R_Gamma.gammaTableBC[i] = parseInt(val);
        this.getGammaLineChart();
    }

    updateCustGammaData() {
        let GammaValue = 0;
        for (let i = 0; i < 4096; i++) {
            GammaValue = this.R_Gamma.gammaTableBC[i];
            $("#GammaValue_" + i).val(GammaValue);
        }
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值