wangzhibo
2021-09-07 89da62649161571834d3f8df7ce36f9967e6ba04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
"use script"; //开发环境建议开启严格模式
 
//对应widget.js中MyWidget实例化后的对象
var thisWidget;
var myChart1; //图表
 
//当前页面业务
function initWidgetView(_thisWidget) {
  thisWidget = _thisWidget;
 
  myChart1 = echarts.init(document.getElementById("echartsView1"), "dark");
  setEchartsData(thisWidget.data);
 
  setInterval(function () {
    updateFlyOk(thisWidget.data);
  }, 800);
}
 
function updateFlyOk(charsData) {
  if (!charsData) {
    return;
  }
 
  var thislen = charsData.thislen || 0;
  var arrFlyOk = []; //已漫游
  for (var i = 0; i < charsData.arrFxgd.length; i++) {
    if (charsData.arrLength[i] <= thislen) {
      arrFlyOk.push(charsData.arrFxgd[i]);
    } else {
      break;
    }
  }
 
  // 填入数据,根据名字对应到相应的系列
  myChart1.setOption({
    series: [{ name: "已漫游", data: arrFlyOk }],
  });
}
 
//飞行漫游 图表
function setEchartsData(charsData) {
  if (charsData == null || myChart1 == null) {
    return;
  }
 
  var option = {
    legend: {
      data: ["地面海拔", "漫游海拔", "已漫游"],
    },
    grid: {
      left: 10,
      right: 10,
      bottom: 10,
      containLabel: true,
    },
    dataZoom: [
      {
        type: "inside",
        throttle: 50,
      },
    ],
    tooltip: {
      trigger: "axis",
      //position: function (point, params, dom, rect, size) {
      //    return [10, 20];
      //},
      formatter: function (params) {
        var inhtml = "";
        if (params.length < 2) {
          return inhtml;
        }
 
        var hbgd = params[0].value; //海拔高度
        var fxgd = params[1].value; //漫游海拔
 
        var point = charsData.arrPoint[params[0].dataIndex]; //所在经纬度
 
        inhtml +=
          "所在位置&nbsp;" +
          point.lng +
          "," +
          point.lat +
          "<br />" +
          params[1].seriesName +
          "&nbsp;<label style='color:" +
          params[1].color +
          ";'>" +
          params[1].value +
          "</label>&nbsp;米<br />";
 
        if (hbgd != 0) {
          inhtml += params[0].seriesName + "&nbsp;<label style='color:" + params[0].color + ";'>" + params[0].value + "</label>&nbsp;米<br />";
          var ldgd = fxgd - hbgd; //离地高度
          inhtml += "距离地面&nbsp;<label>" + ldgd.toFixed(1) + "</label>&nbsp;米";
          // if (charsData.arrBjgd) {
          //     var bjgd = charsData.arrBjgd[params[0].dataIndex];
          //     if (bjgd > fxgd)
          //         inhtml += "(低于报警<label style='color:red;'>&nbsp;" + (bjgd - ldgd).toFixed(1) + "</label>&nbsp;米)";
          // }
        }
 
        return inhtml;
      },
    },
    xAxis: [
      {
        name: "行程",
        type: "category",
        boundaryGap: false,
        axisLine: {
          show: false,
        },
        axisLabel: {
          show: false,
        },
        data: charsData.arrLength,
      },
    ],
    yAxis: [
      {
        //name: '高度',
        type: "value",
        axisLabel: {
          rotate: 60,
          formatter: "{value} 米",
        },
      },
    ],
    series: [
      {
        name: "地面海拔",
        type: "line",
        smooth: true,
        symbol: "none",
        sampling: "average",
        itemStyle: {
          normal: {
            color: "rgb(255, 70, 131)",
          },
        },
        areaStyle: {
          normal: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: "rgb(255, 158, 68)",
              },
              {
                offset: 1,
                color: "rgb(255, 70, 131)",
              },
            ]),
          },
        },
        data: charsData.arrHbgd,
      },
      {
        name: "漫游海拔",
        type: "line",
        smooth: false,
        symbol: "none",
        data: charsData.arrFxgd,
      },
      {
        name: "已漫游",
        type: "line",
        areaStyle: {
          normal: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              {
                offset: 0,
                color: "rgb(255, 255, 0)",
              },
              {
                offset: 1,
                color: "rgb(255, 255, 131)",
              },
            ]),
          },
        },
        data: [],
      },
    ],
  };
 
  // if (charsData.arrBjgd) {
  //     option.legend.data.push('报警高度');
  //     option.series.push({
  //         name: '报警高度',
  //         type: 'line',
  //         smooth: false,
  //         symbol: 'none',
  //         lineStyle: {
  //             normal: {
  //                 width: 2,
  //                 type: 'dotted',
  //                 opacity: 1,
  //             }
  //         },
  //         data: charsData.arrBjgd
  //     });
  // }
 
  myChart1.setOption(option);
}