| | |
| | | |
| | | //当前页面业务 |
| | | function initWidgetView(_thisWidget) { |
| | | thisWidget = _thisWidget |
| | | thisWidget = _thisWidget; |
| | | console.log(thisWidget) |
| | | DatePicker("#appDateHourStart", '#appDateHourEnd'); |
| | | $("#appDateHourStart").datetimepicker("setDate", new Date(thisWidget.appDateHourStart)); |
| | | $('#appDateHourEnd').datetimepicker('setDate', new Date(thisWidget.appDateHourEnd)); |
| | | |
| | | //开始查询历史数据 |
| | | $("#startQueryHistory").click(function () { |
| | | if (myCharts) { |
| | | $('#echart').removeAttr('_echarts_instance_'); |
| | | } |
| | | var backend_url = thisWidget.config.params.nodejs_url_predix + "dataapi/Bdata?bid=get_" + thisWidget.config.params.layerid + "_single_path&datatype=" + thisWidget.config.params.datatype + "&siteid=" + thisWidget.config.params.siteid + "&datatime1=" + thisWidget.appDateHourStart + "&datatime2=" + thisWidget.appDateHourEnd+ "&count=10"; |
| | | // all 1006xx layer has the same legend !! |
| | | var layerid = thisWidget.config.params.layerid+""; |
| | | |
| | | var legendData = all_layer_legends[layerid.substring(0,4)]; |
| | | var legendData_selected = {}; |
| | | legendData.forEach(element => { |
| | | if (element==thisWidget.config.params.selected_qindex.toUpperCase()){ |
| | | legendData_selected[element] =true; |
| | | }else{ |
| | | legendData_selected[element] =false; |
| | | } |
| | | }); |
| | | |
| | | if (legendData == null || legendData.length < 1) { |
| | | return; |
| | | } |
| | | var colorData = echart_lines_color_list[thisWidget.config.params.layerid]; |
| | | var myItemStyle = { |
| | | normal: { |
| | | // 拐点上显示数值 |
| | | label: { |
| | | show: true |
| | | }, |
| | | borderColor: 'red', // 拐点边框颜色 |
| | | lineStyle: { |
| | | width: 2, // 设置线宽 |
| | | type: 'solid' //'dotted'虚线 'solid'实线 |
| | | } |
| | | } |
| | | }; |
| | | $.ajax({ |
| | | type: 'get', |
| | | dataType: 'json', |
| | | data: {}, |
| | | async: false,//同步 |
| | | url: backend_url, |
| | | success: function (data) { |
| | | console.log(data); |
| | | var tableData = data.data.result; |
| | | if (tableData != null && tableData.length > 0) { |
| | | var seriesObj = {}; |
| | | var seriesData = []; |
| | | var timeLineData = []; |
| | | for (var i = 0; i < legendData.length; i++) { |
| | | var singleLegend = legendData[i]; |
| | | var sdata = {}; |
| | | sdata.name = singleLegend; |
| | | sdata.data = []; |
| | | sdata.type = 'line'; |
| | | sdata.symbolSize = 8; |
| | | if (singleLegend.toUpperCase()=='CO'){ |
| | | sdata.yAxisIndex =1; |
| | | } |
| | | sdata.itemStyle = myItemStyle; |
| | | seriesObj[singleLegend] = sdata; |
| | | } |
| | | for (var i = 0; i < tableData.length; i++) { |
| | | var indexObj = tableData[i]; |
| | | timeLineData.push(shortenLegendTimeString(thisWidget.config.params.datatype, indexObj.datatime)); |
| | | for (var j = 0; j < legendData.length; j++) { |
| | | var singleLegend = legendData[j]; |
| | | var sdata = seriesObj[singleLegend]; |
| | | sdata.data.push(indexObj[singleLegend]) |
| | | } |
| | | } |
| | | for (var i = 0; i < legendData.length; i++) { |
| | | var singleLegend = legendData[i]; |
| | | var mySeries = seriesObj[singleLegend]; |
| | | seriesData.push(mySeries); |
| | | } |
| | | |
| | | options = { |
| | | title: { |
| | | text: tableData[0]["name"], |
| | | textStyle: { |
| | | color: '#87CEFA', //颜色 |
| | | }, |
| | | top: '20px', |
| | | x: 'center' |
| | | }, |
| | | legend: { |
| | | // orient 设置布局方式,默认水平布局,可选值:'horizontal'(水平) ¦ 'vertical'(垂直) |
| | | orient: 'horizontal', |
| | | // x 设置水平安放位置,默认全图居中,可选值:'center' ¦ 'left' ¦ 'right' ¦ {number}(x坐标,单位px) |
| | | x: 'center', |
| | | // y 设置垂直安放位置,默认全图顶端,可选值:'top' ¦ 'bottom' ¦ 'center' ¦ {number}(y坐标,单位px) |
| | | y: 'top', |
| | | textStyle: { //图例文字的样式 |
| | | color: '#87CEFA', |
| | | }, |
| | | data: legendData, |
| | | selected:legendData_selected, |
| | | color: 'white' |
| | | }, |
| | | |
| | | // 图表距边框的距离,可选值:'百分比'¦ {number}(单位px) |
| | | grid: { |
| | | top: '20%', // 等价于 y: '16%' |
| | | left: '3%', |
| | | right: '5%', |
| | | bottom: '3%', |
| | | containLabel: true |
| | | }, |
| | | |
| | | // 提示框 |
| | | tooltip: { |
| | | trigger: 'axis' |
| | | }, |
| | | |
| | | toolbox:{ |
| | | feature: { |
| | | saveAsImage: { type:'jpeg'}, |
| | | dataView: {}, |
| | | magicType: { |
| | | type: ['line', 'bar'], |
| | | option: { |
| | | // 类型切换时,下述配置项将被merge到对应类型的图表 series 中 |
| | | line: { smooth: true }, |
| | | bar: { label: { show: true } } |
| | | } |
| | | }, |
| | | } |
| | | }, |
| | | xAxis: { |
| | | name: '时间', |
| | | type: 'category', |
| | | axisLine: { |
| | | lineStyle: { |
| | | // 设置x轴颜色 |
| | | color: '#87CEFA' |
| | | } |
| | | }, |
| | | // 设置X轴数据旋转倾斜 |
| | | axisLabel: { |
| | | color: '#87CEFA', //坐标的字体颜色 |
| | | interval: 0, //设置X轴数据间隔几个显示一个,为0表示都显示 |
| | | formatter: '{value} 时' |
| | | |
| | | }, |
| | | // boundaryGap值为false的时候,折线第一个点在y轴上 |
| | | boundaryGap: false, |
| | | data: timeLineData, |
| | | axisLine: { |
| | | symbol: ['none', 'arrow'], //箭头一端没效果,一端箭头 |
| | | symbolOffset: [0, 8], //箭头段移动8个像素 |
| | | } |
| | | }, |
| | | yAxis: [{ |
| | | name: '指标(μg/m³)', |
| | | type: 'value', |
| | | axisLine: { |
| | | lineStyle: { |
| | | // 设置y轴颜色 |
| | | color: '#87CEFA', |
| | | symbol: ['none', 'arrow'], //箭头一端没效果,一端箭头 |
| | | symbolOffset: [0, 8], //箭头段移动8个像素 |
| | | } |
| | | }, |
| | | },{ |
| | | name: 'CO(mg/m³)', |
| | | type: 'value', |
| | | axisLine: { |
| | | lineStyle: { |
| | | // 设置y轴颜色 |
| | | color: '#8700FA', |
| | | symbol: ['none', 'arrow'], //箭头一端没效果,一端箭头 |
| | | symbolOffset: [0, 8], //箭头段移动8个像素 |
| | | } |
| | | }, |
| | | }], |
| | | series: seriesData, |
| | | color: colorData |
| | | }; |
| | | myCharts = echarts.init(document.getElementById('echart')); |
| | | myCharts.setOption(options, true); |
| | | window.onresize = function(){ |
| | | myCharts.resize(); |
| | | } |
| | | }else{ |
| | | haoutil.msg("无查询记录,请更换查询条件!"); |
| | | } |
| | | }, |
| | | error: function (request, textStatus) { |
| | | haoutil.msg("查询错误,请联系管理员!!!") |
| | | } |
| | | }); |
| | | |
| | | }); |
| | | |
| | | } |
| | | |
| | | // 查询 |
| | | // function resetStartQueryHistoryText(code) { |
| | | // $("#startQueryHistory").text("查询"); |
| | | // } |
| | | |
| | | function DatePicker(beginSelector, endSelector) { |
| | | $(beginSelector).datetimepicker( |
| | | { |
| | | bootcssVer: 3, //bootstrap-datetimepicker+bootstrap v3,但这个插件使用的时候,并没有和V3相匹配,仍然调用的是bootstrap V2的图标 把bootcssVer的值直接设为3,否则datetimepicker不会显示出上、下个月的箭头 |
| | | format: 'yyyy-mm-dd hh:ii:00', |
| | | minView: 'day',//设置时间选择为年月日 去掉时分秒选择 |
| | | todayBtn: true, //如果此值为true 或 "linked",则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。如果是true的话,"Today" 按钮仅仅将视图转到当天的日期,如果是"linked",当天日期将会被选中。 |
| | | clearBtn: true, |
| | | language: 'zh-CN', |
| | | autoclose: true, //当选择一个日期之后是否立即关闭此日期时间选择器。 |
| | | keyboardNavigation: true, //是否允许通过方向键改变日期。 |
| | | forceParse: true, //当选择器关闭的时候,是否强制解析输入框中的值。 |
| | | initialDate: new Date(), |
| | | todayHighlight: 1, //如果为true, 高亮当前日期 |
| | | endDate: new Date() |
| | | }).on('changeDate', function (ev) { |
| | | if (ev.date) { |
| | | $(endSelector).datetimepicker('setStartDate', new Date(ev.date.valueOf())) |
| | | } else { |
| | | $(endSelector).datetimepicker('setStartDate', null); |
| | | } |
| | | thisWidget.appDateHourStart = $(beginSelector).val(); |
| | | }) |
| | | $(endSelector).datetimepicker( |
| | | { |
| | | bootcssVer: 3, //bootstrap-datetimepicker+bootstrap v3,但这个插件使用的时候,并没有和V3相匹配,仍然调用的是bootstrap V2的图标 把bootcssVer的值直接设为3,否则datetimepicker不会显示出上、下个月的箭头 |
| | | format: 'yyyy-mm-dd hh:ii:00', |
| | | todayBtn: true, //如果此值为true 或 "linked",则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。如果是true的话,"Today" 按钮仅仅将视图转到当天的日期,如果是"linked",当天日期将会被选中。 |
| | | clearBtn: true, |
| | | language: 'zh-CN', |
| | | autoclose: true, //当选择一个日期之后是否立即关闭此日期时间选择器。 |
| | | keyboardNavigation: true, //是否允许通过方向键改变日期。 |
| | | forceParse: true, //当选择器关闭的时候,是否强制解析输入框中的值。 |
| | | initialDate: new Date(), |
| | | todayHighlight: 1, //如果为true, 高亮当前日期 |
| | | endDate: new Date() |
| | | }).on('changeDate', function (ev) { |
| | | thisWidget.appDateHourEnd = $(endSelector).val(); |
| | | }) |
| | | } |
| | | |
| | | |
| | | |
| | | ///// |
| | | function reloadData(params) { |
| | | |
| | | loadLineChartbySiteid(params); |
| | |
| | | // 设置X轴数据旋转倾斜 |
| | | axisLabel: { |
| | | color: '#87CEFA', //坐标的字体颜色 |
| | | interval: 0 //设置X轴数据间隔几个显示一个,为0表示都显示 |
| | | interval: 0, //设置X轴数据间隔几个显示一个,为0表示都显示 |
| | | formatter: '{value} 时' |
| | | |
| | | }, |
| | | // boundaryGap值为false的时候,折线第一个点在y轴上 |
| | | boundaryGap: false, |