Echarts按天、按月、按公司統計圖表(備忘)
阿新 • • 發佈:2019-01-10
function drawDayECharts(xArray,array_y1,array_y2,array_y3){ var dom_day = document.getElementById('main_area'); var myChart = echarts.init(dom_day); myChart.off('click'); var option = { tooltip: { trigger: 'axis', axisPointer: { // 座標軸指示器,座標軸觸發有效type: 'shadow' // 預設為直線,可選為:'line' | 'shadow' }, //formatter: '{b0}<br />{a0}: {c0}<br />{a1}: {c1}<br />{a2}: {c2}%' }, legend: { data: ['提交成功', '提交失敗', '提交成功率'] }, grid: { left: '0%', right: '4%', bottom: '3%', containLabel: true }, xAxis: [ { type: 'category', axisTick: {show: false}, data: xArray, } ], yAxis: [ { type: 'value', name: '數量', axisTick: { show: false }, }, { type: 'value', name: '成功率', axisLabel: { formatter: '{value} %' } } ], series: [ { name: '提交成功', type: 'bar', stack: '提交', color: '#6edaee', data: array_y1 }, { name: '提交失敗', type: 'bar', stack: '提交', color: '#d4d4d3', data: array_y2 }, { name: "提交成功率", type: 'line', yAxisIndex: 1, color: '#00a2e6', data: array_y3 } ] }; option.tooltip.formatter = function (params) { console.log(params); return '20'+params[0].name.substr(0,2)+'年'+params[0].name.substr(3,2)+'月'+params[0].name.substr(6,2)+'日'+'<br />' +params[0].seriesName+':'+params[0].value+'<br />' +params[1].seriesName+':'+params[1].value+'<br />' +params[2].seriesName+':'+params[2].value+'%'; } myChart.clear(); myChart.setOption(option); $(dom_day).sizeChanged(myChart.resize); } function drawMonthECharts(xArray,array_y1,array_y2,array_y3){ var dom_month = document.getElementById('main_area'); var myChart = echarts.init(dom_month); myChart.off('click'); var option = { tooltip: { trigger: 'axis', axisPointer: { // 座標軸指示器,座標軸觸發有效 type: 'shadow' // 預設為直線,可選為:'line' | 'shadow' }, //formatter: '{b0}<br />{a0}: {c0}<br />{a1}: {c1}<br />{a2}: {c2}%' }, legend: { data: ['提交成功', '提交失敗', '提交成功率'] }, grid: { left: '0%', right: '4%', bottom: '3%', containLabel: true }, xAxis: [ { type: 'category', axisTick: {show: false}, data: xArray, } ], yAxis: [ { type: 'value', name: '數量', axisTick: { show: false }, }, { type: 'value', name: '成功率', axisLabel: { formatter: '{value} %' } } ], series: [ { name: '提交成功', type: 'bar', stack: '提交', clickable:false, color: '#6edaee', data: array_y1 }, { name: '提交失敗', type: 'bar', stack: '提交', clickable:false, color: '#d4d4d3', data: array_y2 }, { name: "提交成功率", type: 'line', yAxisIndex: 1, clickable:false, color: '#00a2e6', data: array_y3 } ] }; option.tooltip.formatter = function (params) { console.log(params); return params[0].name.substr(0,4)+'年'+params[0].name.substr(5,2)+'月'+'<br />' +params[0].seriesName+':'+params[0].value+'<br />' +params[1].seriesName+':'+params[1].value+'<br />' +params[2].seriesName+':'+params[2].value+'%'; } myChart.clear(); myChart.setOption(option); $(dom_month).sizeChanged(myChart.resize); } function drawComECharts(xArray,array_y1,array_y2,service_type,date_start,date_end,company_id){ var dom_com = document.getElementById('main_area'); var myChart = echarts.init(dom_com); var option = { tooltip: { trigger: 'axis', axisPointer: { // 座標軸指示器,座標軸觸發有效 type: 'shadow' // 預設為直線,可選為:'line' | 'shadow' }, //formatter: '{b0}<br />{a0}: {c0}<br />{a1}: {c1}<br />{a2}: {c2}%' }, legend: { data: ['提交成功', '提交失敗'] }, grid: { left: '0%', right: '4%', bottom: '3%', containLabel: true }, xAxis: [ { type: 'category', axisTick: {show: false}, data: xArray, } ], yAxis: [ { type: 'value', name: '數量', axisTick: { show: false }, }, ], series: [ { name: '提交成功', type: 'bar', stack: '提交', color: '#6edaee', data: array_y1 }, { name: '提交失敗', type: 'bar', stack: '提交', color: '#d4d4d3', data: array_y2 }, ] }; option.tooltip.formatter = function (params) { console.log(params); return params[0].name+'<br />' +params[0].seriesName+':'+params[0].value+'<br />' +params[1].seriesName+':'+params[1].value; } myChart.clear(); myChart.setOption(option); myChart.on('click', function (params) { //console.log(params); //console.log(service_type); //console.log(date_start); //console.log(date_end); window.location.href = "stat_user_company.php?service_type=" + service_type + "&dimension_type=0" + "&date_start=" + date_start + "&date_end=" + date_end + "&company_id=" + company_id[params.dataIndex]; }); $(dom_com).sizeChanged(myChart.resize); } (function ($) { $.fn.sizeChanged = function (handleFunction) { var element = this; var lastWidth = element.width(); var lastHeight = element.height(); setInterval(function () { if (lastWidth === element.width() && lastHeight === element.height()) return; if (typeof (handleFunction) == 'function') { element.height(element.width()*2/5); handleFunction(); lastWidth = element.width(); lastHeight = element.height(); } }, 100); return element; }; }(jQuery));