123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- <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: Object,
- default: () => {}
- },
- // eva: {
- // type: String,
- // default: ''
- // }
- },
- data() {
- return {
- chartObj: null,
- ooption: {
- xdata: [],
- sdata: [],
- },
- name:['100分','90-99分','80-89分','70-79分','60-69分','0-59分'],
- option: {
- xAxis: {
- type: 'value',
- show: false,
- // max: 500
- },
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- // Use axis to trigger tooltip
- type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
- }
- },
- grid: {
- left: '15%',
- right: '5%',
- bottom: '5%',
- top: '5%',
- },
- yAxis: {
- inverse: true,
- type: 'category',
- data: [
- // '三(1)班级',
- // '三(2)班级',
- // '三(3)班级',
- // '三(4)班级',
- // '三(5)班级',
- // '三(6)班级'
- ]
- },
- series: [
- // {
- // showBackground: true,
- // stack: 'total',
- // data: [
- // 40, 30, 40, 50, 60, 70
- // ],
- // type: 'bar'
- // },
- // {
- // showBackground: true,
- // stack: 'total',
- // data: [
- // 20, 10, 26, 51, 44, 35
- // ],
- // type: 'bar'
- // },
- // {
- // showBackground: true,
- // stack: 'total',
- // data: [
- // 11, 23, 41, 15, 23, 14
- // ],
- // type: 'bar'
- // },
- // {
- // showBackground: true,
- // stack: 'total',
- // data: [
- // 41, 21, 21, 12, 24, 34
- // ],
- // type: 'bar'
- // },
- // {
- // showBackground: true,
- // stack: 'total',
- // data: [
- // 52, 54, 53, 24, 35, 43
- // ],
- // 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.yAxis.data = option.xdata;
- this.option.series = []
- for(var i = 0;i<this.name.length;i++){
- this.option.series.push(
- {
- name:this.name[i],
- showBackground: true,
- stack: 'total',
- data: [],
- type: 'bar'
- },
- );
- }
- for(var i = 0;i<option.sdata.length;i++){
- for(var j = 0;j<this.option.series.length;j++){
- this.option.series[j].data.push(option.sdata[i][j])
- }
- }
- console.log(this.option);
- // 初始化雷达图
- this.chartObj = chartObj;
- this.chartObj.setOption(this.option);
- });
- },
- setArray(array) {
- // this.setChart(array);
- // return
- this.ooption = {
- xdata: array.class,
- sdata: array.Array,
- }
- // 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.yAxis.data = this.ooption.xdata;
- this.option.series = []
- for(var i = 0;i<this.name.length;i++){
- this.option.series.push(
- {
- name:this.name[i],
- showBackground: true,
- stack: 'total',
- data: [],
- type: 'bar'
- },
- );
- }
- for(var i = 0;i<this.ooption.sdata.length;i++){
- for(var j = 0;j<this.option.series.length;j++){
- this.option.series[j].data.push(this.ooption.sdata[i][j])
- }
- }
- console.log(this.option);
- 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>
-
|