Echarts3.0加载和订正气象格点数据

前言

主要是对气象格点数据的主观订正,分为两个方面:运用ajax调用接口数据;echarts3.0展示及修改数据。修改后的保存没有涉及,接口的制作没有。

  1. ajax调用数据
function getValues(){
     var type = "TMP";//取温度
        var apoint = arguments[4] ? arguments[4] : 20;// 设置参数point的默认值为20
        var pdata = {
            "point" : apoint
        }; 

         $.ajax({
             type : "post",
             async : true,            //异步请求(同步请求将会锁住浏览器,用户其他操作必须等待请求完成才可以执行)
             url : 接口 + type,   //请求发送处
             data : pdata,
             dataType : "json",        //返回数据形式为json
             success : function(result) {
                 //请求成功时执行该函数内容,result即为服务器返回的json对象
                 if (result) {           
                        var pointsarr = result.points;//获取温度格点
                        showTrend(pointsarr);//调用展示函数
                 }
            },
             error:function(errorMsg) {
                 //请求失败时执行该函数
             alert("图表请求数据失败!");
             }
        })

}

2 . Echarts的设置
(1)折线图X,Y轴的设置

xAxis: [{
            type: 'category',
            splitNumber:24,//划分为24个间隔
            boundaryGap: false,
            data: categories,
        },
        axisLine:{//x轴的横坐标边框线
            show: false
         },axisTick:{
            show: false,
         },axisLabel:{
            show:true,
            textStyle:{
                fontSize:"8px",
                color:"black",
                align:"center"
            },formatter:function(e){
                return e;
            }
         },
         splitLine: {//x轴内置表格中“边框”的颜色线条 
            show: true,
            lineStyle:{
            color:"#e4e4e4",
            type:"solid",
            opacity:"0.75"
                }
            }
        }
        ],

        yAxis: [{
            min: 6,
            max: 20,
            type: 'value',
            splitNumber: 7,
            axisLine:{
                show: true,
                lineStyle:{
                     color:"#e4e4e4"
                  }
                },axisTick:{
                    show: false,
                },axisLabel:{
                    show:true,
                    textStyle:{
                        fontSize:"8px",
                        color:"black"
                    }
                },
           splitLine: {//y轴内置表格中“边框”的颜色线条 
                show: true,
           lineStyle:{
                color:"#e4e4e4",
                type:"solid",
                opacity:"0.75"
                        }
                    }
                }
           ],

(2)折线图网格的设置

series: [
            {
                id: 'a',
                type: 'line',
                smooth: true,
                symbolSize: symbolSize,
                lineStyle:{//折线的颜色
                    normal: {
                        color:"#1ba0fc",
                        width:1,
                        type:'solid',
                        opacity:"0.75"
                       },
                   },
                   areaStyle: {//颜色渐变
                       normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                               offset: 0,
                               color: 'rgba(40, 182, 252, 0.85)'
                           }, {
                               offset: 1,
                               color: 'rgba(28, 159, 255, 0.2)'
                           }])
                       }
                   },itemStyle:{
                    normal:{
                        color:"#96BBCD",
                        barBorderColor:"#FAFCFD",
                    }
                   },
                data: data //数据
            }
        ],

(3)折线图“上下左右”位置的移动

grid:{
            left:20,
            top:10,
            bottom:20,
            right:10,
            show:true,
            borderColor:"#e4e4e4",//网格边框线
            shadowColor:"#e4e4e4",
            borderWidth:"0.2",
            containLabel: false
        } 

(4)echarts的setOption

myChart.setOption({
        graphic: echarts.util.map(data, function (item, dataIndex) {
            return {
                type: 'circle',
                position: myChart.convertToPixel('grid', item),
                shape: {
                    r: symbolSize / 2,//拖拽圆点设置大小
                },
                invisible: true,
                draggable: true,
                ondrag: echarts.util.curry(onPointDragging, dataIndex),//调用拖拽函数
                onmousemove: echarts.util.curry(showTooltip, dataIndex),//鼠标移入显示数据
                onmouseout: echarts.util.curry(hideTooltip, dataIndex),//隐藏
                z: 100
            };
        })

    });

    window.addEventListener('resize', function () {
        myChart.setOption({
            graphic: echarts.util.map(data, function (item, dataIndex) {
                return {
                    position: myChart.convertToPixel('grid', item)
                };
            })
        });
    });

    function showTooltip(dataIndex) {//显示鼠标移入圆圈点的数值
        myChart.dispatchAction({
            type: 'showTip',
            seriesIndex: 0,
            dataIndex: dataIndex
        });
    }

    function hideTooltip(dataIndex) {//隐藏
        myChart.dispatchAction({
            type: 'hideTip'
        });
    }

    function onPointDragging(dataIndex, dx, dy) {
        data[dataIndex] = myChart.convertFromPixel('grid', this.position);
        myChart.setOption({
            series: [{
                id: 'a',
                data: data
            }]
        });
        var dataValues = data;
        localStorage.setItem("data", JSON.stringify(dataValues));//修改后数据放入缓存
    }

测试效果图
结果

源码:由于篇幅太长,在同名的另一篇博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值