| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <template>
- <div class="data_body">
- <div style="width: 100%; height: 100%">
- <div id="charts_canvas" class="echart" style="width: 100%; height: 100%; "></div>
- </div>
- </div>
- </template>
-
- <script>
- export default {
- props: {
- yearArray: {
- type: Array,
- },
- },
- data() {
- return {
- chartObj: null,
- ooption: {
- xdata: [],
- sdata: [],
- },
- option: {
- title: {
- text: '在线时长',
- textStyle:{
- fontSize: 12,
- },
- padding: [10, 0, 0, 10]
- },
- tooltip: {
- position: 'top'
- },
- grid: {
- top: '50',
- left: '5%',
- right: '5%',
- bottom: '5%',
- containLabel: true
- },
- xAxis: {
- type: 'category',
- // data: [
- // '1月', '2月', '3月', '4月', '5月', '6月', '7月',
- // '8月', '9月', '10月', '11月', '12月'
- // ],
- data: [],
- splitArea: {
- show: true
- }
- },
- yAxis: {
- type: 'category',
- data: [
- '星期天', '星期一', '星期二', '星期三',
- '星期四', '星期五', '星期六',
- ],
- splitArea: {
- show: true
- },
- },
- visualMap: {
- min: 0,
- max: 10,
- calculable: true,
- orient: 'horizontal',
- right: '10',
- top: '0%'
- },
- series: [
- {
- name: '',
- type: 'heatmap',
- data: [],
- label: {
- show: true
- },
- emphasis: {
- itemStyle: {
- shadowBlur: 10,
- shadowColor: 'rgba(0, 0, 0, 0.5)'
- }
- }
- }
- ]
- },
- };
- },
- methods: {
- setChart(option) {
- // 雷达图显示的标签
- let newPromise = new Promise((resolve) => {
- resolve();
- });
- //然后异步执行echarts的初始化函数
- newPromise.then(() => {
- const chartObj = this.$echarts.init(
- //劳动课程
- this.$el.querySelector("#charts_canvas")
- );
- this.option.xAxis.data = option.xdata;
- this.option.series[0].data = option.sdata;
- this.option.visualMap.max = option.max ? option.max : 0;
- // 初始化雷达图
- this.chartObj = chartObj;
- this.chartObj.setOption(this.option);
- });
- },
- },
- watch: {
- yearArray: {
- immediate: true,
- deep: true,
- handler(newValue, oldValue) {
- this.ooption = {
- xdata: [],
- sdata: [],
- max:0
- }
- let _array = newValue
- let max = []
- for (var i = 0; i < _array.length; i++) {
- this.ooption.xdata.push(_array[i].Month + '月')
- this.ooption.sdata.push([i, 0, _array[i].sun])
- this.ooption.sdata.push([i, 1, _array[i].mon])
- this.ooption.sdata.push([i, 2, _array[i].tue])
- this.ooption.sdata.push([i, 3, _array[i].wed])
- this.ooption.sdata.push([i, 4, _array[i].thur])
- this.ooption.sdata.push([i, 5, _array[i].fri])
- this.ooption.sdata.push([i, 6, _array[i].sat])
- // let _data = [_array[i].Month-1,] //[月份,星期,值]
- max.push(_array[i].sun)
- max.push(_array[i].mon)
- max.push(_array[i].tue)
- max.push(_array[i].wed)
- max.push(_array[i].thur)
- max.push(_array[i].fri)
- max.push(_array[i].sat)
- }
- this.ooption.max = max.sort(function(a,b){
- return b-a;
- })[0];
- if (!this.chartObj) {
- this.setChart(this.ooption);
- } else {
- this.option.xAxis.data = this.ooption.xdata;
- this.option.series[0].data = this.ooption.sdata;
- this.option.visualMap.max = this.ooption.max ? this.ooption.max : 0;
- this.chartObj.setOption(this.option);
- }
- this.$forceUpdate();
- },
- },
- },
- mounted() {
- this.ooption = {
- xdata: [],
- sdata: [],
- max:0
- }
- let _array = this.yearArray
- let max = []
- for (var i = 0; i < _array.length; i++) {
- this.ooption.xdata.push(_array[i].Month + '月')
- this.ooption.sdata.push([i, 0, _array[i].sun])
- this.ooption.sdata.push([i, 1, _array[i].mon])
- this.ooption.sdata.push([i, 2, _array[i].tue])
- this.ooption.sdata.push([i, 3, _array[i].wed])
- this.ooption.sdata.push([i, 4, _array[i].thur])
- this.ooption.sdata.push([i, 5, _array[i].fri])
- this.ooption.sdata.push([i, 6, _array[i].sat])
- // let _data = [_array[i].Month-1,] //[月份,星期,值]
- max.push(_array[i].sun)
- max.push(_array[i].mon)
- max.push(_array[i].tue)
- max.push(_array[i].wed)
- max.push(_array[i].thur)
- max.push(_array[i].fri)
- max.push(_array[i].sat)
- }
- this.ooption.max = max.sort(function(a,b){
- return b-a;
- })[0];
-
- this.setChart(this.ooption);
- var _this = this;
- window.addEventListener("resize", () => {
- if (_this.chartObj) {
- _this.chartObj.resize();
- }
- });
- },
- };
- </script>
-
- <style scoped>
- .data_body {
- height: 100%;
- position: relative;
- border-radius: 5px;
- margin: 0 auto;
- box-sizing: border-box;
- padding: 0;
- width: 95%;
- background: #fff;
- }
- </style>
-
|