123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <template>
- <div shadow="never" class="homeBoxCard" v-loading="loading">
- <div class="height300" id="pieChart" ref="pieChart" />
- </div>
- </template>
- <script>
- import { defineComponent, onMounted, ref ,watch} from 'vue'
- // import { useStore } from 'vuex'
- import * as echarts from 'echarts'
- // var total_datas = 0
- // for (var i = 0; i < echartData.length; i++) {
- // total_datas += Number(echartData[i].value)
- // console.log(typeof echartData[i].value)
- // }
- export default defineComponent({
- name: 'PieChart',
- props: {
- getTableData: Object,
- },
- setup(props) {
- // 读取数据 func
- const loading = ref(true)
- const getData = async () => {
- loading.value = false
- }
- function echarts2() {
- let myChart = echarts.init(document.getElementById('pieChart'))
- // 绘制图表
- myChart.setOption({
- title: [
- {
- text: 1,
- subtext: '共计回路',
- textStyle: {
- fontSize: 24,
- color: 'black',
- },
- subtextStyle: {
- fontSize: 16,
- color: 'black',
- },
- textAlign: 'center',
- left: '49%',
- top: '40%',
- },
- ],
- tooltip: {
- trigger: 'item',
- formatter: function (parms) {
- var str =
- '</br>' +
- parms.marker +
- '' +
- parms.data.legendname +
- '</br>'
- // +
- // '数量:' +
- // parms.data.value +
- // '</br>' +
- // '占比:' +
- // parms.percent +
- // '%'
- return str
- },
- },
- legend: {
- type: 'scroll',
- orient: 'horizontal',
- bottom: '0%',
- align: 'left',
- // top:'middle',
- textStyle: {
- color: '#8C8C8C',
- },
- height: 250,
- },
- series: [
- {
- // name: '标题',
- type: 'pie',
- center: ['50%', '50%'],
- radius: ['37%', '55%'],
- clockwise: false, //饼图的扇区是否是顺时针排布
- avoidLabelOverlap: false,
- label: {
- show: false,
- },
- labelLine: {
- show: false,
- },
- data: [
- {
- value: props.getTableData.score>=80?1:0,
- legendname: '优秀',
- name: '优秀',
- itemStyle: { color: '#40ABFE' },
- },
- {
- value: props.getTableData.score>=60?1:0,
- legendname: '合格',
- name: '合格',
- itemStyle: { color: '#EEAA3F' },
- },
- {
- value: props.getTableData.score<60?1:0,
- legendname: '不合格',
- name: '不合格',
- itemStyle: { color: '#FF2222' },
- },
- ],
- },
- ],
- })
- window.addEventListener('resize', () => {
- myChart.resize()
- })
- }
- const writeValue = (val) => {
- val
- getData()
- echarts2()
- }
- //监听变化
- watch(
- () => props.getTableData,
- (newVal, oldVal, clear) => {
- // 执行异步任务,并得到关闭异步任务的 id
- // console.log(newVal)
- let id = writeValue(newVal, oldVal)
- // 如果 watch 监听被重复执行了,则会先清除上次未完成的异步任务
- clear(() => clearTimeout(id))
- },
- { lazy: true }
- )
- onMounted(() => {
- getData()
- echarts2()
- })
- return {
- loading,
- echarts2,
- }
- },
- })
- </script>
- <style lang="scss" scoped>
- .homeBoxCard {
- margin-bottom: 24px;
- ::v-deep(.el-card__header) {
- padding-left: 12px;
- padding-right: 12px;
- }
- ::v-deep(.el-card__body) {
- padding: 12px;
- font-size: 14px;
- line-height: 1.5715;
- }
- ::v-deep(.el-divider) {
- margin: 8px 0;
- }
- .num {
- font-size: 30px;
- color: #515a6e;
- }
- .height300 {
- height: 300px;
- }
- }
- </style>
|