在 Apache ECharts 中,自定义主题(Theme)通常有三种常见方式:
echarts.init(dom, themeName) + 注册主题主题本质上是一个 JSON 配置对象,示例如下:
const myTheme = {
color: ['#5470c6', '#91cc75', '#fac858', '#ee6666'],
backgroundColor: '#f5f5f5',
title: {
textStyle: {
color: '#333'
}
},
legend: {
textStyle: {
color: '#666'
}
},
tooltip: {
backgroundColor: '#fff',
borderColor: '#ccc'
}
};
echarts.registerTheme('myTheme', myTheme);
const chart = echarts.init(
document.getElementById('main'),
'myTheme'
);
theme.json{
"color": ["#5470c6", "#91cc75"],
"backgroundColor": "#ffffff",
"textStyle": {}
}
fetch('theme.json')
.then(res => res.json())
.then(theme => {
echarts.registerTheme('custom', theme);
const chart = echarts.init(
document.getElementById('main'),
'custom'
);
});
✅ 官方地址:
https://echarts.apache.org/zh/theme-builder.html
操作步骤:
JS / JSONregisterTheme| 配置项 | 说明 |
|---|---|
color |
系列默认颜色 |
backgroundColor |
画布背景 |
title / legend / tooltip |
各组件样式 |
categoryAxis / valueAxis |
坐标轴样式 |
series |
可全局覆盖系列样式 |
initsetOption(option, true) 强制覆盖如果你有 具体场景(如:暗黑主题、企业蓝、移动端),我可以直接帮你写一套完整主题配置。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。