var token = $.cookie("token"); var hjCompaer; //图形 $(document).ready(function() { //日期 laydate.render({ elem: '#chooseTime', type: 'year', range: '~', max: '1', theme: '#00a1cb' }); var preYears = new Date().getFullYear() - 1; var nowYears = new Date().getFullYear(); $('#chooseTime').val(preYears + ' ~ ' + nowYears) Ajax(); //导出功能 $('.export').click(function() { dcexcel(this); }) //搜索事件 $(".sear").click(function() { if($('#chooseTime').val() == '') { layer.confirm('请选择对比时间!', { btn: ['确定'] }); return; } Ajax(); }); }); hjCompaer = echarts.init(document.getElementById('hjCompaer')); var option = { tooltip: { trigger: 'axis', }, legend: { data: [], bottom: 0 }, xAxis: [{ type: 'category', data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'], axisPointer: { type: '' } }], yAxis: [{ type: 'value', name: '电话数量', nameLocation: 'middle', nameGap: 40, // min: 0, // max: 10000, // interval: 1000, axisLabel: { formatter: '{value} ' } }, { type: 'value', name: '百分比', nameLocation: 'middle', nameGap: 35, // min: 0, // max: 100, // interval: 10, axisLabel: { formatter: '{value} ' } } ], series: [{ name: '', type: 'bar', yAxisIndex: 0, data: [] }, { name: '', type: 'bar', yAxisIndex: 0, data: [] }, { name: '', type: 'line', yAxisIndex: 1, data: [] }, { name: '', type: 'bar', yAxisIndex: 0, data: [] }, { name: '', type: 'bar', yAxisIndex: 0, data: [] }, { name: '', type: 'line', yAxisIndex: 1, data: [] } ], color: ['#1ab394', '#adcbfd', '#fbbe5b', '#f26ea2', '#88ebc4', '#fa957f'] }; hjCompaer.setOption(option); function Ajax() { var arr = []; var allData = []; $.ajax({ type: 'get', url: huayi.config.callcenter_url + 'YearContrast/GetDataList', dataType: 'json', data: { token: token, beginyear: $('#chooseTime').val() && $('#chooseTime').val().split('~')[0], endyear: $('#chooseTime').val() && $('#chooseTime').val().split('~')[1] }, async: false, success: function(res) { var content = res.data; $.each(content, function(index, ele) { arr.push(content[index].key) allData.push(content[index].value) }); option.legend.data = arr; //图例 //添加数据name for(var i = 0; i < arr.length; i++) { option.series[i].name = arr[i]; } //添加图形数据 for(var j = 0; j < allData.length; j++) { option.series[j].data = allData[j]; } hjCompaer.setOption(option); } }); } //导出功能 function dcexcel(obj) { var url = huayi.config.callcenter_url + "YearContrast/ExptList?token=" + $.cookie("token"); url += "&beginyear=" + ($('#chooseTime').val() ? $('#chooseTime').val().split('~')[0] : '') + "&endyear=" + ($('#chooseTime').val() ? $('#chooseTime').val().split('~')[1] : ''); obj.href = url; }