123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <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: {
- loginArray: {
- type: Array
- },
- },
- data() {
- return {
- chartObj: null,
- ooption: {
- xdata: [],
- type: [],
- },
- option: {
- tooltip: {
- trigger: 'item'
- },
- series: [
- {
- type: 'pie',
- radius: ['80%', '100%'],
- avoidLabelOverlap: false,
- itemStyle: {
- borderRadius: 10,
- borderColor: '#fff',
- borderWidth: 2
- },
- label: {
- show: true,
- position: 'center',
- // formatter: '{b}\n{c}'
- fontSize: 20,
- rich: {
- a: {
- fontSize: 30,
- },
- b: {
- lineHeight: 20,
- fontSize: 14,
- color: '#00000099'
- }
- }
- // formatter: function (params) {
- // console.log(params);
- // var sum = 0;
- // for (var i = 0; i < params.data.length; i++) {
- // sum += params.data[i].value;
- // }
- // return sum + '\n表单总数';
- // }
- },
- emphasis: {
- label: {
- show: true,
- fontSize: 20,
- rich: {
- a: {
- fontSize: 30,
- },
- b: {
- lineHeight: 20,
- fontSize: 14,
- color: '#00000099'
- }
- }
- // formatter: '{c}'
- }
- },
- labelLine: {
- show: false
- },
- hoverOffset: 0, // 设置鼠标悬停时不放大
- data: [
- { value: 10, name: '进行中', itemStyle: { normal: { color: '#3673e8' } } },
- { value: 8, name: '未发布', itemStyle: { normal: { color: '#61b8ff' } } },
- { value: 6, name: '已完成', itemStyle: { normal: { color: '#96d8a8' } } },
- { value: 7, name: '逾期', itemStyle: { normal: { color: '#f5b763' } } },
- ]
- }
- ]
- },
- };
- },
- methods: {
- setChart(array) {
- // 雷达图显示的标签
- let newPromise = new Promise((resolve) => {
- resolve();
- });
- //然后异步执行echarts的初始化函数
- newPromise.then(() => {
- const chartObj = this.$echarts.init(
- this.$el.querySelector("#charts_canvas")
- );
- // this.option.series[0].data = array;
- let _this = this
- _this.option.series[0].label.emphasis = _this.option.series[0].label.formatter = function (params) {
- console.log(params);
- var sum = 0;
- for (var i = 0; i < _this.option.series[0].data.length; i++) {
- sum += _this.option.series[0].data[i].value;
- }
- return '{a|' + sum + '}\n{b|表单总数}';
- }
- // 初始化雷达图
- _this.chartObj = chartObj;
- _this.chartObj.setOption(_this.option);
- });
- },
- setJson(array) {
- this.ooption = {
- xdata: [],
- sdata: [],
- max: 0
- }
- if (!this.chartObj) {
- this.setChart(array);
- } else {
- this.option.series[0].data = array;
- this.chartObj.setOption(this.option);
- }
- }
- },
- watch: {
- loginArray: {
- immediate: true,
- deep: true,
- handler(newValue, oldValue) {
- this.setJson(newValue)
- this.$forceUpdate();
- },
- },
- },
- mounted() {
- this.setJson(this.loginArray)
- 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: 100%;
- /* background: #fff; */
- }
- </style>
|