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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
| $(function () { resizeContainer(); echart = echarts.init(container); buildDatepicker(); bulidTags(); showLine();
$('#addLine').on('click', showLine); $('#clearCharts').on('click', clearCharts); $('#updateCharts').on('click', update); resize(); });
var container = document.getElementById('main'); var tags; var echart; var option = { grid: { top: '10%', left: '5%' }, title: { text: '机票每分钟订单量' }, tooltip: { trigger: 'axis' }, toolbox: { show: true, feature: { dataView: { show: true }, restore: { show: true }, dataZoom: { show: true }, saveAsImage: { show: true }, magicType: { type: ['bar', 'line'] } } }, legend: { data: [] }, dataZoom: [ { type: 'slider', xAxisIndex: 0, start: 0, end: 100 }, { type: 'inside', xAxisIndex: 0, start: 0, end: 100 }, { type: 'slider', yAxisIndex: 0, start: 0, end: 100 }, { type: 'inside', yAxisIndex: 0, start: 0, end: 100 } ], xAxis: { data: getDateArray(), axisPointer: { show: true } }, yAxis: {}, series: [] };
function getDateArray(endDate, splitTime, count) { if (!endDate) { endDate = new Date('2000-01-01 23:59:00'); } if (!splitTime) { splitTime = 60 * 1000; } if (!count) { count = 1440; } var endTime = endDate.getTime(); var mod = endTime % splitTime; if (mod > 0) { endTime -= mod; } var dateArray = []; while (count-- > 0) { var d = new Date(); d.setTime(endTime - count * splitTime); dateArray.push(checkTime(d.getHours()) + ':' + checkTime(d.getMinutes()) + ":00"); } return dateArray; }
function checkTime(i) { if (i < 10) { i = "0" + i; } return i; }
function showLine() { var someday = $('#dateInput').val(); if (!someday) { someday = '2017-06-01' } if (option.legend.data.length > 4) { BootstrapDialog.alert('<p class="imporMsg">不能多于5条数据</p>'); return; } if ($.inArray(someday, option.legend.data) >= 0) { return; }
tags.addTag(someday); $.ajax({ type: 'GET', url: '/flight_minute_orders/date/' + someday }).done(function (res) { if (res && res.data) { var tempSeries = {}; tempSeries.name = someday; tempSeries.type = 'line'; tempSeries.calculable = true; tempSeries.data = []; res.data.forEach(function (ele, index) { tempSeries.data.push(ele['orderNum']); }); option.legend.data.push(someday); option.series.push(tempSeries); echart.setOption(option); } }); }
function clearCharts() { var length = tags.tagData.length; for (var i = 0; i < length; i++) { tags.removeLastTag(); } }
function resizeContainer() { container.style.width = (window.innerWidth - 300) + 'px'; container.style.height = (window.innerHeight - 100) + 'px'; }
function resize() { window.onresize = function () { resizeContainer(container); echart.resize(); }; }
function buildDatepicker() { $("#datetimepicker").datepicker({ format: "yyyy-mm-dd", startDate: '2017-06-01', endDate: '2017-06-21', autoclose: true, language: 'zh-CN' }); }
function bulidTags() { tags = $('#my-tag-list').tags({ tagData: ["2017-06-01"], promptText: "显示在图表中的日期列表", tagSize: 'lg', afterDeletingTag: function (tag) { if ($.inArray(tag, option.legend.data) >= 0) { option.legend.data = option.legend.data.filter(function (item) { return tag !== item; }); option.series = option.series.filter(function (item) { return tag !== item.name; }); echart.setOption(option, true); } } }); }
function update() { if (option.series.length === 0) { BootstrapDialog.alert('<p class="imporMsg">没有数据,无法更新</p>'); return; }
BootstrapDialog.show({ size: 'size-wide', title: '请确认', message: $('<div class="imporMsg">确定要更新到数据库吗?</div>'), buttons: [{ label: '确认', cssClass: 'btn btn-primary', action: function (dialog) { var modelList = []; var currentSeries = option.series; echart.getOption().series.forEach(function (ele) { var dateArray = getDateArray(); var currentSerie = currentSeries.shift(); ele.data.forEach(function (ele2) { var currentTime = dateArray.shift(); if (parseInt(ele2) !== currentSerie.data.shift()) { var model = {}; model.datetime = ele.name + " " + currentTime; model.orderNum = ele2; modelList.push(model); } }); }); if (modelList.length > 0) { $.ajax({ type: 'POST', data: JSON.stringify(modelList), contentType: 'application/json; charset=utf-8', url: '/flight_minute_orders/update' }).done(function (res) { if (res.status === 0) { dialog.close(); BootstrapDialog.alert('<p class="imporMsg">更新成功!</p>'); } }); } else { dialog.close(); BootstrapDialog.alert('<p class="imporMsg">数据已是最新的!</p>'); } } }] }); }
|