echart vue

article/2025/9/8 5:50:30

文档:

https://echarts.apache.org/zh/tutorial.html#5%20%E5%88%86%E9%92%9F%E4%B8%8A%E6%89%8B%20ECharts

1、条形

<template><div> <!-- 包其他内容需要有个外div --><div :class="className" :style="{height:height,width:width}" id="sortEChart"/></div>
</template><script>import echarts from 'echarts'require('echarts/theme/macarons') // echarts themeexport default {props: {className: {type: String,default: 'chart'},width: {type: String,default: '100%'},height: {type: String,default: '335px'}},data() {return {chart: null}},mounted() {this.$nextTick(() => {this.initChart()})},beforeDestroy() {if (!this.chart) {return}this.chart.dispose()this.chart = null},methods: {initChart() {// this.chart = echarts.init(this.$el, 'macarons')this.chart = echarts.init(document.getElementById('sortEChart'))this.chart.setOption({tooltip: {trigger: 'axis',axisPointer: {type: 'shadow'}},legend: {bottom: 0,data: ['本地', '外地']},grid: {left: '3%',right: '4%',bottom: '10%',containLabel: true},xAxis: {type: 'category',data: ['新鲜水果', '新鲜蔬菜', '新鲜肉类', '冻品类', '粮油干货', '休闲食品', '调味品类', '禽蛋类']},yAxis: {type: 'value',boundaryGap: [0, 0.01]},series: [{name: '本地',type: 'bar',data: [10, 25, 50, 75, 99, 50, 60, 75],color: '#6495F9'},{name: '外地',type: 'bar',data: [10, 25, 50, 75, 99, 50, 65, 75],color: '#69DFAE'}]})}}}
</script>

2、圆形

<template><div><div :class="className" :style="{height:height,width:width}" id="purchaseEChart"/></div>
</template>
<script>
import echarts from 'echarts'require('echarts/theme/macarons') // echarts themeexport default {props: {className: {type: String,default: 'chart'},width: {type: String,default: '100%'},height: {type: String,default: '335px'}},data() {return {chart: null}},mounted() {this.$nextTick(() => {this.initChart()})},beforeDestroy() {if (!this.chart) {return}this.chart.dispose()this.chart = null},methods: {initChart() {// this.chart = echarts.init(this.$el, 'macarons')this.chart = echarts.init(document.getElementById('purchaseEChart'))this.chart.setOption({tooltip: {trigger: 'item',formatter: '{a} <br/>{b} : {c} ({d}%)'},legend: {orient: 'vertical',top: 50,height: '60%',right: '2%',data: ['新鲜蔬菜', '冻品类', '糖油干货', '奶类', '干货类','休闲食品', '调味品类', '蛋类', '水果类', '新鲜肉类']},series: [{name: '占比',type: 'pie',radius: '55%',center: ['35%', '50%'],selectedMode: 'single',data: [{ value: 33, name: '新鲜蔬菜', itemStyle: { color: '#03BD5B' }},{ value: 18, name: '冻品类', itemStyle: { color: '#F5A623' }},{ value: 9, name: '糖油干货', itemStyle: { color: '#F1453D' }},{ value: 7, name: '奶类', itemStyle: { color: '#785549' }},{ value: 8, name: '干货类', itemStyle: { color: '#B9D337' }},{ value: 7, name: '休闲食品', itemStyle: { color: '#1EBEA5' }},{ value: 6, name: '调味品类', itemStyle: { color: '#6744B1' }},{ value: 5, name: '蛋类', itemStyle: { color: '#FED630' }},{ value: 4, name: '水果类', itemStyle: { color: '#339AED' }},{ value: 3, name: '新鲜肉类', itemStyle: { color: '#28E5FD' }}],label: {normal: {// {b}代表显示的内容标题// {c}代表数据值// {d}代表占百分比// formatter: '{b}:{d}%',formatter: '{d}%',borderWidth: 20,borderRadius: 4}},emphasis: {itemStyle: {shadowBlur: 10,shadowOffsetX: 0,shadowColor: 'rgba(0, 0, 0, 0.5)'}}}]})}}
}
</script>

3、仪表盘 type: 'gauge',    

<template><div :class="className" :style="{height:height,width:width}" />
</template><script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts themeexport default {props: {className: {type: String,default: 'chart'},width: {type: String,default: '100%'},height: {type: String,default: '172px'},query: {type: Object,default: function() {const obj = {date: '',name: ''}return obj}}},data() {return {chart: null}},mounted() {this.$nextTick(() => {this.initChart()})},beforeDestroy() {if (!this.chart) {return}this.chart.dispose()this.chart = null},methods: {initChart() {this.chart = echarts.init(this.$el, 'macarons')var that = thisif (isNaN(that.query.date) || that.query.date === null) {that.query.date = 0}this.chart.setOption({series: [{name: '1',type: 'gauge',center: ['50%', '55%'], // 默认全局居中radius: '45%',startAngle: 314.99,min: 0,max: 400, // 分母splitNumber: 10,axisLine: { // 坐标轴线lineStyle: { // 属性lineStyle控制线条样式color: [[295.6 / 400, '#FF4343'], // 根据实际数据动态改变[1, '#DDDDDD']],width: 6, // 半径shadowColor: '#fff', // 默认透明shadowBlur: 1}},pointer: {show: false},axisLabel: {show: true,// 坐标轴小标记textStyle: { // 属性lineStyle控制线条样式fontWeight: 'bolder',color: 'transparent', // 刻度数字颜色 隐藏shadowColor: '#fff', // 默认透明shadowBlur: 10}},axisTick: { // 坐标轴小标记length: 11, // 属性length控制线长lineStyle: { // 属性lineStyle控制线条样式color: 'transparent', // 坐标轴 小刻度线颜色shadowColor: '#fff', // 默认透明shadowBlur: 10}},splitLine: { // 分隔线length: 20, // 属性length控制线长lineStyle: { // 属性lineStyle(详见lineStyle)控制线条样式width: 3,color: 'transparent', // 分割线shadowColor: '#fff', // 默认透明shadowBlur: 10}},title: {textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLEfontSize: 12,color: '#000',shadowColor: '#fff', // 默认透明shadowBlur: 10},offsetCenter: ['0', '175%']},detail: { // show : true ,borderColor: '#fff',shadowColor: '#fff', // 默认透明textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLEfontWeight: 'bolder',fontSize: 16,color: '#000'  // 字体颜色},formatter: '{value}',  // 格式化最终的展现offsetCenter: ['0', '10%']},data: [{value: 20.1,name: "蛋白质(g)"}]}]})}}
}
</script>
<style lang="scss"></style>

4、 字体适配
FontChart(res) {
        //获取到屏幕的宽度
        var clientWidth =
          window.innerWidth ||
          document.documentElement.clientWidth ||
          document.body.clientWidth; 
        if (!clientWidth) return; //报错拦截:
        let fontSize = 1 * (clientWidth / 1920);
        return res * fontSize;
      },

textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE// fontWeight: 'bolder',fontSize: this.fontChart(40),color: '#237CFA' // 字体颜色
},


http://chatgpt.dhexx.cn/article/TggQoXE0.shtml

相关文章

Vue + Echarts自定义图标颜色及柱状图动态伸缩(定时)

1、效果图&#xff1a; 2、Vue代码 <template><!--区域分布数量柱状图--><div class"emp-area"></div> </template><script>require(/assets/theme/chalk)require(echarts/theme/macarons)export default {name: "StaffA…

如何使用pyecharts中的主题样式?

如何使用pyecharts中的主题样式&#xff1f; pyechart为用户提供了一套使用方便的主题风格。 本篇图文将总结pyecharts.globals中ThemeType所有主题风格并进行详细的解释。 class _ThemeType:BUILTIN_THEMES ["light", "dark", "white"]LIGH…

python亲和数_用 Python 分析了 5 万条相亲数据,告诉你男女相亲背后的秘密

作者| 叶庭云 责编 | 张文 来源 | 转载自修炼 Python(ID&#xff1a;yetingyun_python) 前言 数据来源&#xff1a;https://www.zhenai.com/zhenghun/ 本文利用 Python 分析了按城市寻找所有地区的征婚信息&#xff0c;看看相亲男女的画像。 数据查看和预处理 导入用到的库 …

vue中echarts使用案例:饼图(可直接使用)

目录 功能、效果图&#xff1a; 代码实现 1、下载echarts包&#xff1a;终端运行 2、代码 3.运行项目&#xff1a;终端运行 4、可能遇到的错误 具体代码详解&#xff1a; 功能、效果图&#xff1a; 1.点击对应模块&#xff0c;放大并显示数据 2、点击下方图标&#xff0c…

Python绘制柱状图之可视化神器pyecharts(一)

目录 pyecharts介绍 特性 优势 展示 柱状图模板系列 水晶柱状图 解决X轴标签过长的柱状图 自定义平均刻度标签&#xff08;方便查看超出范围&#xff09; 翻转X Y轴柱状图 可以移动的X轴柱状图&#xff08;适合数据类别过多&#xff09; 可以移动的Y轴柱状图&#x…

已解决:vue echart 动态获取数据且定时刷新

文章目录 写在前面需求①需求②需求③无效的解决办法1&#xff1a;无效的解决办法2有效的解决办法 写在前面 我太难了&#xff0c;搞一个echart仪表盘&#xff0c;需求一步步分解&#xff1a; ①一开始是写死的假数据&#xff0c;图表成功显示在页面上; ②和后台约定数据类型格…

Python绘制柱状图之可视化神器pyecharts(二)

目录 主题介绍 图表参数 主题详解 柱状图模板系列 海量数据柱状图动画展示 收入支出柱状图&#xff08;适用于记账&#xff09; 我们在日常的生活中&#xff0c;有收入也有支出&#xff0c;这个模板就是把收入和支出直观的展示在读者面前。 三维数据叠加 柱状图与折线…

day07 pyecharts制图

目录 Python配置安装pyecharts 一、柱状图的使用二、折线图三、饼图四、地图五、词云六、组合图 Python配置安装pyecharts Python配置国内镜像源 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple pycharm配置pyecharts 一、柱状图的使用 # 导入…

vue-echarts主题切换+选择面板实现

通过实现主题选择面板&#xff0c;更方便的对echarts图表进行主题的切换&#xff0c;并且支持饼状图、折线图、柱状图等多类型echarts图表。 目录 1、实现过程 1.1、导入echarts主题JS文件 1.2、添加选择按钮图片 1.3、添加按钮 1.4、主题选择面板实现 1.5、初始化echart…

echarts 2.0 macarons主题安装

2019独角兽企业重金招聘Python工程师标准>>> 主题下载: http://echarts.baidu.com/doc/example/theme/macarons.js 其他主题改名字就好了.[无责任猜测] 这里采用AMD加载方式 [博主用的是requirejs] 在main.js中 require.config({paths:{echarts:js/echarts/echarts…

魔法值及魔法值处理方法

魔法值 什么是魔法值 所谓的魔法值就是在代码中直接出现的数字。   PS&#xff1a;代码中有魔法值会造成代码可读性低&#xff08;与代码量成正比&#xff09;。还会造成维护困难&#xff0c;改动一个数值便要大动干戈&#xff0c;牵一发而动全身。应当尽力消灭或减少魔法值…

别让【魔法值】毁了你的代码!

二分钟&#xff0c;教你一个写代码的好习惯。 大家好&#xff0c;我是鱼皮&#xff0c;今天通过一件事情&#xff0c;分享写代码时的一个重要小技巧。 前段时间&#xff0c;我在编程导航项目中开源了一段代码&#xff0c;实现的功能是&#xff0c;当用户的操作失败时&#xff…

【java】万恶的魔法值

在最近的小云通知项目中&#xff0c;我负责维护后端的开发&#xff0c;也是深刻体会到用魔法值会给维护人员带来多大的痛苦&#xff01;可谓一个bug改一天…… 文章目录 什么是魔法值怎么处理魔法值 什么是魔法值 首先我们说一下什么是魔法值&#xff0c;所谓魔法值&#xff0…

什么是java中的魔法值

自从在idea上用了 《阿里巴巴Java开发手册》的插件之后 这里附上对应的插件安装方法&#xff1a;https://developer.aliyun.com/article/224817 偶然发现自己的代码中出现了所谓的 “魔法值” 什么是魔法值呢 所谓魔法值&#xff0c;就是在代码中直接出现的数值&#xff0c;只…

Java中的魔法值和解决方法

目录 一、什么是魔法值 二、解决方法 一、什么是魔法值 魔法数值、魔法数字、魔法值&#xff0c;这是一个东西&#xff0c;不同的叫法。 所谓魔法值&#xff0c;是指在代码中直接出现的数值&#xff0c;只有在这个数值记述的那部分代码中才能明确了解其含义&#xff0c;数字…

java 不要使用魔法值_为什么阿里巴巴Java开发手册中不允许魔法值出现在代码中?...

武培轩 推荐搜索 JavaSpring Boot数据结构MySQLElasticsearchNginx 在阅读《阿里巴巴Java开发手册》时&#xff0c;发现有一条关于关于常量定义的规约&#xff0c;具体内容如下&#xff1a; 图中的反例是将数据缓存起来&#xff0c;并使用魔法值加链路 id 组成 key&#xff0c;…

java 项目减少魔法值_项目代码中魔法值的优雅处理

经常在代码里面会用一些表示有意义的数字&#xff0c;但是如果不写注释的话&#xff0c;过了一段时间我们自己再回去优化代码的时候&#xff0c;可能自己也不清楚这些数字表示的是什么意思了。 如果写注释的话&#xff0c;就要每次使用数字的时候都要写注释了&#xff0c;这样的…

java 魔法值_Java 开发技巧:减少魔法值的使用

1. 前言 重构老代码中遇到了类似这种写法&#xff1a; public void attend(String value){ if ("0".equals(value)) { //todo } else if ("1".equals(value)) { //todo } else { //todo } } 脑壳疼&#xff01;从 Java 语法上无懈可击&#xff0c;但是从业…

IDEA快速去除魔法值

背景 写代码有的时候为了方便&#xff0c;会在代码里面留下很多字符串之类的变量。这种便便会被定义为魔法值。 这种变量正常来讲不影响阅读的。所以一般情况下&#xff0c;我们都不会去处理它。 但是当项目越来越大的时候&#xff0c;我们发现很多地方都有可能使用了同一个…

魔法值与解决办法

1.什么是魔法值 魔法值是指代码中突然出现的数字&#xff0c;之所以称为魔法值&#xff0c;是因为这个20可以有多种意义。在新来的员工接手你的代码时&#xff0c;他们产生疑问&#xff1a;为什么要设这个20&#xff0c;背后有什么秘密吗。大大降低了代码的可维护性。 2.解决办…