123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <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: {
- evCourseArray: {
- type: Array,
- default: []
- },
- eva: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- chartObj: null,
- ooption: {
- xdata: [],
- sdata: [],
- },
- option: {
- xAxis: {
- type: 'value',
- show:false,
- },
- grid:{
- left: '15%',
- right: '5%',
- bottom: '5%',
- top: '5%',
- },
- yAxis: {
- inverse: true,
- type: 'category',
- data: [
- '休闲状态(<=50%)',
- '热身状态(50-60%)',
- '脂肪燃烧(60-70%)',
- '心肺提升(70-80%)',
- '乳酸闽值(80-90%)',
- '极限无氧(>=90%)'
- ]
- },
- series: [
- {
- showBackground: true,
- data: [
- {
- value: 10,
- itemStyle: {
- color: 'rgb(157, 157, 157)'
- }
- },
- {
- value: 20,
- itemStyle: {
- color: 'rgb(15, 216, 242)'
- }
- },
- {
- value: 40,
- itemStyle: {
- color: 'rgb(0, 208, 146)'
- }
- },
- {
- value: 80,
- itemStyle: {
- color: 'rgb(255, 192, 29)'
- }
- },
- {
- value: 70,
- itemStyle: {
- color: 'rgb(247, 123, 1)'
- }
- },
- {
- value: 15,
- itemStyle: {
- color: 'rgb(255, 58, 32)'
- }
- },
- ],
- type: 'bar'
- }
- ]
- },
- };
- },
- methods: {
- setChart(option) {
- // 雷达图显示的标签
- let newPromise = new Promise((resolve) => {
- resolve();
- });
- //然后异步执行echarts的初始化函数
- newPromise.then(() => {
- const chartObj = this.$echarts.init(
- //劳动课程
- this.$el.querySelector("#charts_canvas")
- );
- // this.option.radar.indicator = option.xdata;
- // this.option.series[0].data[0].value = option.sdata;
- // 初始化雷达图
- this.chartObj = chartObj;
- this.chartObj.setOption(this.option);
- });
- },
- setArray(array) {
- this.setChart(array);
- return
- this.ooption = {
- xdata: [],
- sdata: [],
- }
- for (var i = 0; i < array.length; i++) {
- if (array[i].evid == this.eva) {
- this.ooption.xdata = array[i].indicator
- this.ooption.sdata = array[i].value
- break;
- }
- }
- setTimeout(() => {
- // if (!this.chartObj) {
- this.setChart(this.ooption);
- // } else {
- // this.option.radar.indicator = this.ooption.xdata;
- // this.option.series[0].data[0].value = this.ooption.sdata;
- // this.chartObj.setOption(this.option);
- // }
- }, 100);
- this.$forceUpdate();
- },
- },
- watch: {
- evCourseArray: {
- immediate: true,
- deep: true,
- handler(newValue, oldValue) {
- this.setArray(newValue)
- this.$forceUpdate();
- },
- },
- eva: {
- immediate: true,
- deep: true,
- handler(newValue, oldValue) {
- this.setArray(this.evCourseArray)
- this.$forceUpdate();
- },
- },
- },
- mounted() {
- this.setArray(this.evCourseArray)
- // this.setChart(this.ooption);
- var _this = this;
- window.addEventListener("resize", () => {
- if (_this.chartObj) {
- _this.chartObj.resize();
- }
- });
- },
- };
- </script>
-
- <style scoped>
- .data_body {
- height: 100%;
- /* display: flex; */
- position: relative;
- border-radius: 5px;
- /* border: 1px solid #eee; */
- margin: 0 auto;
- box-sizing: border-box;
- padding: 0;
- width: 95%;
- background: #fff;
- }
- </style>
-
|