123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <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: {
- EscoreArray2: {
- type: Array,
- },
- },
- data() {
- return {
- chartObj: null,
- ooption: {
- xdata: [],
- sdata: [],
- },
- option: {
- xAxis: {
- // data: ['一年级一班', '一年级二班', '一年级三班', '一年级四班', '一年级五班', '一年级六班', '一年级七班']
- data: []
- },
- tooltip: {
- formatter: function (params, ticket, callback) {
- return `${params.marker + params.name}</br>最高分:${params.value[2]}</br>最低分:${params.value[1]}`;
- }
- },
- dataZoom: [
- {
- // start: 50,
- type: 'inside',
- },
- {
- type: 'slider',
- }
- ],
- yAxis: {},
- grid: {
- top: '5%',
- left: '0%',
- right: '0%',
- bottom: '13%',
- containLabel: true
- },
- series: [
- {
- type: 'candlestick',
- data: [
- // [70, 80, 70, 80],
- // [60, 90, 60, 90],
- // [50, 80, 50, 80],
- // [78, 88, 78, 88],
- // [85, 98, 85, 98],
- // [75, 95, 75, 95],
- // [65, 100, 65, 100],
- // [55, 99, 55, 99]
- ],
- itemStyle: {
- color: '#17C469',
- borderColor: null
- }
- }
- ]
- },
- };
- },
- 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;
- chartObj.off('click')
- let _this = this
- chartObj.on('click', function (param) {
- console.log(param); //X轴的值
- _this.$emit('openDataClass', param.dataIndex)
- });
- // 初始化雷达图
- this.chartObj = chartObj;
- this.chartObj.setOption(this.option);
- });
- },
- setArray(Array) {
- this.ooption = {
- xdata: [],
- sdata: [],
- }
- let _array = Array
- for (var i = 0; i < _array.length; i++) {
- this.ooption.xdata.push(_array[i].name)
- this.ooption.sdata.push([_array[i].min, _array[i].max, _array[i].min, _array[i].max])
- }
- if (!this.chartObj) {
- this.setChart(this.ooption);
- } else {
- this.option.xAxis.data = this.ooption.xdata;
- this.option.series[0].data = this.ooption.sdata;
- this.chartObj.setOption(this.option);
- }
- }
- },
- watch: {
- EscoreArray2: {
- immediate: true,
- deep: true,
- handler(newValue, oldValue) {
- this.setArray(newValue)
- this.$forceUpdate();
- },
- },
- },
- mounted() {
- this.setArray(this.EscoreArray2)
- 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>
-
|