news 2026/4/23 5:05:14

echarts4升级为echarts5的常见问题

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
echarts4升级为echarts5的常见问题

[ECharts] DEPRECATED: textStyle hierarchy in label has been removed since 4.0. All textStyle properties are configured in label directly now.

[ECharts]已弃用:标签中的textStyle层次结构自4.0以来已被删除。现在,所有textStyle属性都直接在标签中配置。

https://blog.csdn.net/qq_33489538/article/details/140325353

https://www.cnblogs.com/tanxj/p/18070040

series: [

{

type: 'map',

label: {

textStyle: { // textStyle 删除,没有这个属性了

fontSize: 13,

fontWeight: 600,

color: '#000',

}

}

}

]

emphasis 下是没有 textStyle 属性

emphasis: {

show: true, // 官方:是否显示标签; 自己的理解: 区域hover是否显示省份/直辖市等名称

textStyle: { // textStyle 删除,没有这个属性了

color: '#000' // hover时显示的省份/市等名称的颜色

}

}

axisLabel 中的 textStyle 层次结构已被删除

[ECharts] DEPRECATED: textStyle hierarchy in axisLabel has been removed since 4.0. All textStyle properties are configured in axisLabel directly now.

弃用:axisLabel中的textStyle层次结构自4.0以来已被删除。现在,所有textStyle属性都直接在axisLabel中配置。

axisLabel: { textStyle: { color: '#333', fontSize: 14 } }

ECharts 4.0 及之后 (新版写法)

axisLabel: { color: '#333', fontSize: 14 }

修改前 (旧版写法)

xAxis: {

type: 'category',

data: ['Mon', 'Tue', 'Wed'],

axisLabel: {

show: true,

textStyle: { // 需要移除的层级

color: '#333',

fontSize: 14,

fontStyle: 'italic'

}

}

}

修改后 (新版写法)

xAxis: {

type: 'category',

data: ['Mon', 'Tue', 'Wed'],

axisLabel: {

show: true,

color: '#333', // 原 textStyle 下的属性

fontSize: 14, // 直接提升到 axisLabel 下

fontStyle: 'italic' // 直接提升到 axisLabel 下

}

}

也就是去掉xAxis和 yAxis 的 textStyle,

title: 标题下面是有 textStyle 不要去掉

visualMap下是有textStyle属性的

visualMap: [

{

left: 40,

top: '4%',

seriesIndex: 1,

textStyle: {

color: '#333', // 圆点右侧的文字颜色

}

}

]

tooltip.textStyle 下是有textStyle属性的

tooltip: {

textStyle: {

color: '#333333',

fontSize: 12,

height: 42

}

}

title 下是有textStyle属性的

title: {

text: '标题',

top: 20, // 相对容器顶部的距离值

padding: [0, 0, 0, 20],

textStyle: { // 设置主标题的文字风格

color: '#333333', // 字体颜色

fontSize: 16, // 文字大小

fontWeight: 600,

},

itemGap: 20

},

legend 下的textStyle是存在的

legend: {

type: 'scroll',

orient: 'horizontal',

// textStyle: {

fontSize: 14,

color: '#333333', // 设置图例文本颜色

padding: [3, 0, 0, 0],

// },

data: backData.legend

}

itemStyle.emphasis已经被弃用

[ECharts] DEPRECATED: itemStyle.emphasis has been changed to emphasis.itemStyle since 4.0

弃用:itemStyle.emphasis 自4.0以来已更改为emphasis.itemStyle

itemStyle.emphasis ==> 更改为: emphasis.itemStyle

‌错误写法示例‌:

itemStyle: {

emphasis: {

color: 'red'

}

}

‌正确写法‌:

emphasis: {

itemStyle: {

color: 'red'

}

}

错误的写法

itemStyle: {

// 地图边框设置

normal: {

areaColor: '#D9D9D9', // 每个区域的颜色

borderColor: '#FFFFFF', // 每个区域的描边颜色

borderWidth: 0.5 // 每个区域的描边宽度

},

// hover效果

emphasis: {

borderColor: '#5c5c5c',

borderWidth: 0.5,

areaColor: {

type: 'linear',

x: 0,

y: 0,

x2: 0,

y2: 1,

colorStops: [

{

offset: 0,

color: '#D9D9D9' // 0% 处的颜色

}

],

globalCoord: false // 缺省为 false

}

}

},

正确的写法

itemStyle: {

// 地图边框设置

normal: {

areaColor: '#D9D9D9', // 每个区域的颜色

borderColor: '#FFFFFF', // 每个区域的描边颜色

borderWidth: 0.5 // 每个区域的描边宽度

},

},

// hover效果

emphasis: {

itemStyle:{

borderColor: '#5c5c5c',

borderWidth: 0.5,

areaColor: {

type: 'linear',

x: 0,

y: 0,

x2: 0,

y2: 1,

colorStops: [

{

offset: 0,

color: '#D9D9D9' // 0% 处的颜色

}

],

globalCoord: false // 缺省为 false

}

}

},

lineStyle.normal 属性已经被删除

[ECharts] DEPRECATED: 'normal' hierarchy in lineStyle has been removed since 4.0. All style properties are configured in lineStyle directly now.

[ECharts]已弃用:lineStyle中的“normal”层次结构自4.0以来已被删除。现在可以直接在lineStyle中配置所有样式特性

如果你之前是这样配置的:

series: [{

type: 'line',

lineStyle: {

normal: { // 应该被删除

color: 'green',

width: 2

}

}

}]

你应该将其修改为:

series: [{

type: 'line',

lineStyle: {

color: 'green',

width: 2

}

}]

itemStyle下没有normal

[ECharts] DEPRECATED: label.emphasis has been changed to emphasis.label since 4.0

DEPRECATED:从4.0开始,label.emphas 改为 emphasis.label

参考地址:https://zhuanlan.zhihu.com/p/526439319

旧版本:

"itemStyle": {

"normal": {

"areaColor": "#eeeeee",

"borderColor": "#999999",

"borderWidth": "0.5"

},

},

新版本:

"itemStyle": {

"areaColor": "#eeeeee",

"borderColor": "#999999",

"borderWidth": "0.5"

},

itemStyle下没有normal

[ECharts] DEPRECATED: 'normal' hierarchy in itemStyle has been removed since 4.0. All style properties are configured in itemStyle directly now.

index.vue:116[ECharts]已弃用:itemStyle中的“正常”层次结构自4.0以来已被删除。现在可以直接在itemStyle中配置所有样式属性。

写法(已废弃):

itemStyle: {

normal: {

color: '#62B4FF'

}

}

新版本正确写法:

itemStyle: {

color: '#62B4FF'

}

label下没有normal

DEPRECATED: 'normal' hierarchy in label has been removed since 4.0. All style properties are configured in label directly now.

自4.0以来,标签中的“normal”层次结构已被删除。现在,所有样式属性都直接在标签中配置。

ECharts 4.0 之前 label: { normal: { show: true, position: 'inside', color: '#fff' } }

ECharts 4.0 及之后 label: { show: true, position: 'inside', color: '#fff' }

修改前 (旧版写法):

label: {

normal: {

show: true,

position: 'inside',

color: '#fff',

fontSize: 12

}

}

修改后 (新版写法):

label: {

show: true,

position: 'inside',

color: '#fff',

fontSize: 12

}

series: [

{

// 地图块的配置相关信息

type: 'map',

map: nameMap,

zoom: 1.2,

// 地图上各个省份的名称哈

label: {

normal: {

show: true, // false隐藏省份的名称

// 各个区域-省/市名称样式设置 label下面现在没有textStyle

textStyle: {

fontSize: 13,

fontWeight: 600,

color: '#000'

}

},

// 文字hover颜色

emphasis: {

show: true, // 是否在高亮状态下显示标签。

textStyle: {

color: '#000'

} // 高亮状态下的标签文本样式。

}

},

}

]

更改为

label: {

// normal: {

show: true, // false隐藏省份的名称哈

// 各个区域-省份/市名称样式设置

// textStyle: {

fontSize: 13,

fontWeight: 600,

color: '#000',

// }

// },

// 文字hover颜色

// emphasis: {

// show: true, // 是否在高亮状态下显示标签。

// textStyle: {

// color: '#000'

// } // 高亮状态下的标签文本样式。

// }

},

echarts初始化时,没有宽度和高度

Can't get DOM width or height. Please check dom.clientWidth and dom.clientHeight. They should not be 0.For example, you may need to call this in the callback of window.onload

无法获取DOM宽度或高度。请检查dom.clientWidth和dom.clientHeight。它们不应该是0。例如,您可能需要在window.onload的回调中调用它

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/22 1:40:34

Llama-Index RAG 进阶:小索引大窗口 + 混合检索 + 智能路由实战指南

Llama-Index RAG进阶检索策略实战指南 你的 RAG 为何总是“答非所问”?打破从 Demo 到生产的最后一道墙 “明明 Demo 跑得好好的,怎么一上线就‘翻车’?” 这是无数开发者在构建 RAG(检索增强生成)应用时面临的真实崩…

作者头像 李华
网站建设 2026/4/17 17:12:36

亚马逊卖家容易失误的3个坑,有人这样做亏了10w!

亚马逊卖家最怕的:不是赚得少,而是低级失误直接赔到倾家荡产! 分享刷到一个去年的真实案例,简直让人看完背后发凉😱:有个运营想给产品冲销量,先在站外社交平台扔了个折扣码。结果没过一两个小时…

作者头像 李华
网站建设 2026/4/18 19:39:53

直接上手玩转遗传算法,先搞个简单的函数最值问题热热身。比如找f(x)=x²的最小值,这玩意儿小学生都能秒答,但咱们用遗传算法折腾一下。先看看种群初始化代码

#MATLAB编写遗传算法,基于遗传算法求解TSP问题及函数最值最值问题。 #程序包含详细注释,本人在2020a版本均可运行。% 种群初始化 population_size 50; gene_length 20; % 二进制编码长度 population randi([0 1], population_size, gene_length); 这里…

作者头像 李华
网站建设 2026/4/18 14:38:28

【光照】[PBR][镜面反射]实现方法解析

微表面理论的核心概念微表面理论是一种物理渲染模型,它将宏观表面视为由无数微观几何细节(微表面)组成的复杂结构。这一理论是Unity URP中PBR(基于物理的渲染)实现的基础。基本假设‌微观结构‌:宏观表面由…

作者头像 李华
网站建设 2026/4/17 19:52:23

JavaScript学习笔记:15.迭代器与生成器

JavaScript学习笔记:15.迭代器与生成器 上一篇用类型数组搞定了二进制数据的“高效存储”,这一篇咱们解锁JS遍历的“终极形态”——迭代器(Iterators)与生成器(Generators)。你肯定用过for循环遍历数组&…

作者头像 李华
网站建设 2026/4/17 2:00:50

探索Comsol/CST狄拉克半金属BDS超材料:Matlab脚本与CST模型分享

Comsol/CST狄拉克半金属BDS超材料。 matlab脚本,送几个CST模型嘿,各位技术同好们!今天来聊聊超有趣的Comsol/CST狄拉克半金属BDS超材料。狄拉克半金属近年来在材料物理和电磁学领域那可是相当热门,而基于它的BDS超材料更是展现出独…

作者头像 李华