当前位置: 首页 > news >正文

echarts 各类统计图 高分辨下文字模糊

目录

一、问题

二、原因及解决方法

三、总结


如嫌繁琐,可直接移步至总结

一、问题

1.统计页面中多处用到echarts渲染统计图,在高分辨的大屏幕下 统计图及内部文字显示模糊

如下图所示:

二、原因及解决方法

1.模糊原因:为了能够渲染echarts图形,设置了固定的宽度和高度。而且高度和宽度必须设置。

2.echarts默认使用 canvas渲染,高分辨下会失真,改为  svg 渲染即可(不同分辨率下都不会失真)

3.具体方法:

echarts.init(echartRef.value, null, {
    renderer: 'svg'
  })

4.具体代码如下:

<template>
  <div class="purchase-drug-type rounded-t-2xl">
    <div class="flex items-center justify-center pb-24px pl-10px flex-auto bg-white rounded-2xl w-[400px] h-[300px]">
      <div ref="echartRef" class="echart w-full h-[264px]"></div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref, computed } from 'vue'
import * as echarts from 'echarts'

import type { Module4 } from '@/api/chainBoard.api'

const props = withDefaults(defineProps<{ module: Module4; unit: string }>(), {
  unit: '%'
})
// const chartData = computed(() => {
//   return props.module?.propotion?.map((element) => ({
//     name: element.drugTypeName,
//     value: element.ratio
//   }))
// })

const echartRef = ref(null)
let myChart = ref()
onMounted(async () => {
  await initData()
})

function initData() {
  myChart.value = echarts.init(echartRef.value, null, {
    render: 'svg'
  })
  myChart.value.setOption({
    tooltip: {
      trigger: 'item',
      formatter: (params: any) => {
        return `<div style="display:flex;justify-content:space-between;align-items:center">
          <div style="margin-right:16px">
            <span style="display:inline-block;margin-right:2px;border-radius:10px;width:10px;height:10px;background-color:${params.color};"></span>
           <span >${params.name}</span></div>
          <div>${params.value}${props.unit}</div>
        </div>`
      }
    },
    color: ['#FCAB25', '#FFD200', '#AED823', '#10DFB5', '#FE6200', '#91cc75', '#fac858', '#ee6666', '#73c0de'],
    series: [
      {
        type: 'pie',
        radius: ['50%', '59%'],
        avoidLabelOverlap: true,
        padAngle: 1,
        itemStyle: {
          borderRadius: 10
        },

        emphasis: {
          label: {
            show: true,
            fontWeight: 'bold',
            fontSize: 16,
            formatter: (params: any) => {
              return `{emphasisStyle|${params.name}}\n{emphasisStyle|${params.value}${props.unit}}`
            },
            rich: {
              emphasisStyle: {
                align: 'left',
                fontSize: 16,
                fontWeight: 'bold'
              }
            }
          }
        },
        label: {
          show: true,
          color: '#000000',
          lineHeight: 20,

          formatter: (params: any) => {
            return `{nameStyle|${params.name}}\n{valueStyle|${params.value}${props.unit}}`
          },
          rich: {
            nameStyle: {
              align: 'left',
              fontSize: 14,
              lineHeight: 20
            },
            valueStyle: {
              align: 'left',
              fontSize: 14,
              lineHeight: 20
            }
          }
        },

        labelLine: {
          length2: 45,
          length: 10,
          marginBottom: 2,
          lineStyle: {
            width: 3
          },
          minSurfaceAngle: 100,
          maxSurfaceAngle: 90
        },
        data: testData
      }
    ]
  })
}

const testData = [
  {
    name: 'test1',
    value: '11'
  },
  {
    name: 'test2',
    value: '21'
  },
  {
    name: 'test3',
    value: '21'
  },
  {
    name: 'test4',
    value: '21'
  },
  {
    name: 'test5',
    value: '21'
  }
]
</script>
<style lang="less" scoped>
.purchase-drug-type {
  background: linear-gradient(180deg, #fefbf8 0%, #fef8f4 100%);
  width: 300px;
  height: 300px;
}
</style>

5.最终效果

三、总结

对于echarts渲染模糊,可以尝试改为 svg 方式渲染

  myChart.value = echarts.init(echartRef.value, null, {

    render: 'svg'

  })

/*

希望对你有帮助!

如有错误,欢迎指正!

*/

http://www.dtcms.com/a/109049.html

相关文章:

  • SpringBoot全局exception处理最佳实践
  • MySQL深入
  • P10744 [SEERC 2020] Modulo Permutations 题解
  • 基于Contiue来阅读open-r1中的GRPO训练代码
  • 【Pandas】pandas DataFrame select_dtypes
  • SpringBoot3 整合 Elasticsearch
  • 思维链编程模式下可视化医疗编程具体模块和流程架构分析(全架构与代码版)
  • HMI 设计:提升工业设备操作的便捷性与安全性
  • 网络编程—Socket套接字(UDP)
  • 通过发音学英语单词:从音到形的学习方法
  • 用ChatGPT-5自然语言描述生成完整ERP模块
  • 工作记录 2017-03-24
  • ollama导入huggingface下载的大模型并量化
  • 11_常用函数
  • Golang的文件同步与备份
  • HLS入门之点灯大师
  • IPIP.NET-IP地理位置数据
  • 1. 购物车
  • Sentinel[超详细讲解]-7 -之 -熔断降级[异常比例阈值]
  • 万字重谈C++——类和对象篇
  • JAVA并发编程高级--深入解析 Java ReentrantLock:非公平锁与公平锁的实现原理
  • 【零基础入门unity游戏开发——2D篇】2D 游戏场景地形编辑器——TileMap的使用介绍
  • 虚拟电商-话费充值业务(六)话费充值业务回调补偿
  • MINIQMT学习课程Day3
  • Enovia许可配置和优化
  • seaweedfs分布式文件系统
  • RAC磁盘头损坏问题处理
  • 特征金字塔网络(FPN)详解
  • 【易订货-注册/登录安全分析报告】
  • Oracle触发器使用(二):伪记录和系统触发器