123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <template>
- <div class="inspectionStatisticsEcharts" id="inspectionStatisticsEcharts-box"></div>
- </template>
- <script>
- import { checkStatistics } from '@/apiDemo/safetyCheck/index'
- export default {
- name: 'inspectionStatisticsEcharts',
- data(){
- return{
- }
- },
- created(){
- },
- mounted(){
- this.eCharts();
- },
- methods:{
- //eCharts方法
- eCharts(){
- checkStatistics().then(response => {
- let data = {
- name : [],
- standards : [],
- notStandards : [],
- }
- for(let i=0;i<response.rows.length;i++){
- data.name.push(response.rows[i].yearMonth)
- if(response.rows[i].notStandards.indexOf('%') != -1){
- response.rows[i].notStandards = response.rows[i].notStandards.split('%')[0]
- data.notStandards.push(response.rows[i].notStandards)
- }else{
- data.notStandards.push(response.rows[i].notStandards)
- }
- if(response.rows[i].standards.indexOf('%') != -1){
- response.rows[i].standards = response.rows[i].standards.split('%')[0]
- data.standards.push(response.rows[i].standards)
- }else{
- data.standards.push(response.rows[i].standards)
- }
- }
- let myChart = this.$echarts.init(document.getElementById('inspectionStatisticsEcharts-box'));
- let option = {
- //你的代码
- tooltip: {
- show:true,
- trigger: 'axis',
- formatter: function(params) {
- let html = '<div>';
- html += '<p>'+params[0].name+'</p>'
- for(let i=0;i<params.length;i++){
- html += '<p>'+params[i].marker+' '+params[i].seriesName+' : '+params[i].data+'%<p>'
- }
- return html;
- },
- axisPointer: {
- lineStyle: {
- color: 'rgb(126,199,255)',
- },
- },
- },
- legend: {
- show: true,
- icon: 'circle',
- itemWidth: 30,
- itemHeight: 10,
- right:20,
- textStyle: {
- color: 'rgba(0, 0, 0, 1)',
- fontSize: 14,
- padding: [0, 8, 0, 8]
- }
- },
- grid: {
- top: '20%',
- left: '10%',
- right: '7%',
- bottom: '15%',
- },
- xAxis: [
- {
- type: 'category',
- boundaryGap: false,
- axisLine: {
- show: true,
- lineStyle: {
- color: 'rgb(41,188,245)',
- },
- },
- axisLabel: {
- textStyle: {
- color: 'rgba(112, 151, 184, 1)',
- fontSize: 12,
- },
- },
- splitLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- data: data.name,
- },
- ],
- yAxis: [
- {
- name: "",
- nameTextStyle: {
- color: "#fff",
- fontSize: 12,
- padding: [0, 60, 0, 0]
- },
- // minInterval: 1,
- type: 'value',
- splitLine: {
- show: false,
- },
- axisLine: {
- show: false,
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: 'rgba(112, 151, 184, 1)',
- fontSize: 14
- }
- },
- axisTick: {
- show: false,
- },
- },
- ],
- series: [
- {
- name: '符合',
- type: 'line',
- symbol: 'circle',
- smooth: true,
- lineStyle: {
- normal: {
- width: 1,
- color: '#00AEFF', // 线条颜色
- },
- },
- showSymbol: false,
- itemStyle: {
- normal: {
- color: '#00AEFF',//拐点颜色
- label: {
- show: false, //开启显示
- color: '#fff',
- position: 'top', //在上方显示
- formatter: function (res) {
- console.log('res',res)
- if (res.value) {
- return res.value
- } else {
- return 0
- }
- },
- },
- },
- },
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [ // 渐变颜色
- {
- offset: 0,
- color: 'rgba(0,174,255,1)',
- },
- {
- offset: 0.5,
- color: 'rgba(0,174,255,0.38)',
- },
- {
- offset: 1,
- color: 'rgba(0,174,255,0)',
- },
- ],
- global: false,
- },
- },
- data: data.standards,
- },
- {
- name: '不符合',
- type: 'line',
- symbol: 'circle', // 默认是空心圆(中间是白色的),改成实心圆
- smooth: true,
- lineStyle: {
- normal: {
- width: 1,
- color: '#F66F00', // 线条颜色
- },
- },
- showSymbol: false,
- itemStyle: {
- normal: {
- color: '#F66F00',//拐点颜色
- label: {
- show: true, //开启显示
- color: '#fff',
- position: 'top', //在上方显示
- formatter: function (res) {
- if (res.value) {
- return res.value
- } else {
- return 0
- }
- },
- },
- },
- },
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [ // 渐变颜色
- {
- offset: 0,
- color: 'rgba(246,111,0,1)',
- },
- {
- offset: 0.5,
- color: 'rgba(246,111,0,0.38)',
- },
- {
- offset: 1,
- color: 'rgba(246,111,0,0)',
- },
- ],
- global: false,
- },
- },
- data: data.notStandards,
- }
- ]
- };
- myChart.setOption(option);
- })
- },
- }
- }
- </script>
- <style scoped>
- .inspectionStatisticsEcharts{
- height:236px;
- }
- </style>
|