| | |
| | | <template> |
| | | <!-- <div> --> |
| | | <!-- <div>1111111111111111111111111111111111111111</div> --> |
| | | <div :class="className" :style="{height:height,width:width}" /> |
| | | <div :class="className" :style="{ height: height, width: width }" /> |
| | | <!-- </div> --> |
| | | </template> |
| | | |
| | |
| | | props: { |
| | | className: { |
| | | type: String, |
| | | default: 'chart' |
| | | default: 'chart', |
| | | }, |
| | | width: { |
| | | type: String, |
| | | default: '100%' |
| | | default: '100%', |
| | | }, |
| | | height: { |
| | | type: String, |
| | | default: '350px' |
| | | default: '350px', |
| | | }, |
| | | autoResize: { |
| | | type: Boolean, |
| | | default: true |
| | | default: true, |
| | | }, |
| | | chartData: { |
| | | type: Object, |
| | | required: true |
| | | } |
| | | required: true, |
| | | }, |
| | | // xdata: { |
| | | // type: Array, |
| | | // required: true |
| | |
| | | }, |
| | | data() { |
| | | return { |
| | | chart: null |
| | | chart: null, |
| | | } |
| | | }, |
| | | watch: { |
| | | chartData: { |
| | | deep: true, |
| | | |
| | | handler(val) { |
| | | console.log(val,'wath'); |
| | | this.setOptions(val) |
| | | } |
| | | } |
| | | }, |
| | | deep: true, |
| | | |
| | | }, |
| | | }, |
| | | mounted() { |
| | | this.$nextTick(() => { |
| | |
| | | this.setOptions(this.chartData) |
| | | }, |
| | | setOptions(val) { |
| | | console.log(val); |
| | | this.chart.setOption({ |
| | | xAxis: { |
| | | data: val.xAxis, |
| | | boundaryGap: false, |
| | | axisTick: { |
| | | show: false |
| | | } |
| | | }, |
| | | grid: { |
| | | left: 10, |
| | | right: 10, |
| | | bottom: 20, |
| | | top: 30, |
| | | containLabel: true |
| | | }, |
| | | toolbox: { |
| | | feature: { |
| | | dataZoom: { |
| | | yAxisIndex: 'none' |
| | | console.log(val.series,'123'); |
| | | function fontSize(res) { |
| | | let clientWidth = |
| | | window.innerWidth || |
| | | document.documentElement.clientWidth || |
| | | document.body.clientWidth |
| | | if (!clientWidth) return |
| | | let fontSize = 100 * (clientWidth / 1920) |
| | | return res * fontSize |
| | | } |
| | | this.chart.setOption( |
| | | { |
| | | xAxis: { |
| | | data: val.xAxis, |
| | | boundaryGap: false, |
| | | axisTick: { |
| | | show: false, |
| | | }, |
| | | restore: {}, |
| | | saveAsImage: {} |
| | | } |
| | | }, |
| | | // tooltip: { |
| | | // trigger: 'axis', |
| | | // position: function(pt) { |
| | | // return [pt[0], '10%'] |
| | | // } |
| | | // }, |
| | | tooltip: { |
| | | trigger: 'axis', |
| | | position: function(pt) { |
| | | return [pt[0], '10%'] |
| | | }, |
| | | formatter(params) { |
| | | for (let i = 0; i < params.length; i++) { |
| | | return params[i].seriesName + ':' + ' ' + params[i].data.data0 |
| | | } |
| | | } |
| | | }, |
| | | // tooltip: { |
| | | // trigger: 'axis', |
| | | // axisPointer: { |
| | | // type: 'cross' |
| | | // }, |
| | | // padding: [5, 10] |
| | | // }, |
| | | yAxis: { |
| | | axisLabel: { |
| | | show: false |
| | | } |
| | | }, |
| | | legend: { |
| | | icon: 'circle', |
| | | itemHeight: 15, |
| | | // textStyle: { |
| | | // fontSize: 18 |
| | | grid: { |
| | | left: 10, |
| | | right: 10, |
| | | bottom: 20, |
| | | top: 30, |
| | | height: fontSize(3.5), |
| | | containLabel: true, |
| | | }, |
| | | toolbox: { |
| | | feature: { |
| | | dataZoom: { |
| | | yAxisIndex: 'none', |
| | | }, |
| | | restore: {}, |
| | | saveAsImage: {}, |
| | | }, |
| | | }, |
| | | // tooltip: { |
| | | // trigger: 'axis', |
| | | // position: function(pt) { |
| | | // return [pt[0], '10%'] |
| | | // } |
| | | // }, |
| | | data: val.title |
| | | tooltip: { |
| | | trigger: 'axis', |
| | | position: function (pt) { |
| | | return [pt[0], '10%'] |
| | | }, |
| | | formatter(params) { |
| | | console.log(params,'ssss'); |
| | | let data=[] |
| | | for (let i = 0; i < params.length; i++) { |
| | | data+=params[i].seriesName + ' :' +'  '+params[i].value+ '<br/>' |
| | | } |
| | | return data |
| | | }, |
| | | }, |
| | | |
| | | yAxis: { |
| | | axisLabel: { |
| | | show: false, |
| | | }, |
| | | }, |
| | | legend: { |
| | | icon: 'circle', |
| | | itemHeight: 15, |
| | | // textStyle: { |
| | | // fontSize: 18 |
| | | // }, |
| | | data: val.title, |
| | | }, |
| | | dataZoom: [ |
| | | { |
| | | type: 'inside', |
| | | start: 0, |
| | | end: 100, |
| | | }, |
| | | { |
| | | start: 0, |
| | | end: 10, |
| | | top:fontSize(4), |
| | | height: fontSize(0.4), |
| | | }, |
| | | |
| | | ], |
| | | series: val.series, |
| | | // [{ |
| | | // name: JSON.parse(JSON.stringify(val.title)), |
| | | // itemStyle: { |
| | | // normal: { |
| | | // color: '#7AC5CD', |
| | | // lineStyle: { |
| | | // color: '#7AC5CD', |
| | | // width: 2 |
| | | // } |
| | | // } |
| | | // }, |
| | | // smooth: true, |
| | | // type: 'line', |
| | | // data: val.series, |
| | | // animationDuration: 2800, |
| | | // animationEasing: 'cubicInOut', |
| | | // areaStyle: {}, |
| | | // label: { |
| | | // normal: { |
| | | // show: true, |
| | | // position: 'top' |
| | | // } |
| | | // } |
| | | // }] |
| | | }, |
| | | dataZoom: [{ |
| | | type: 'inside', |
| | | start: 0, |
| | | end: 100 |
| | | }, { |
| | | start: 0, |
| | | end: 10 |
| | | }], |
| | | series: val.series |
| | | // [{ |
| | | // name: JSON.parse(JSON.stringify(val.title)), |
| | | // itemStyle: { |
| | | // normal: { |
| | | // color: '#7AC5CD', |
| | | // lineStyle: { |
| | | // color: '#7AC5CD', |
| | | // width: 2 |
| | | // } |
| | | // } |
| | | // }, |
| | | // smooth: true, |
| | | // type: 'line', |
| | | // data: val.series, |
| | | // animationDuration: 2800, |
| | | // animationEasing: 'cubicInOut', |
| | | // areaStyle: {}, |
| | | // label: { |
| | | // normal: { |
| | | // show: true, |
| | | // position: 'top' |
| | | // } |
| | | // } |
| | | // }] |
| | | }, true) |
| | | } |
| | | } |
| | | true |
| | | ) |
| | | }, |
| | | }, |
| | | } |
| | | </script> |