蓝戒博客

  • 首页
  • 研发说
  • 架构论
  • 效能录
  • AI谈
  • 随笔集
智构苍穹
融合 AI、架构与工程实践,沉淀方法论,构建可持续的技术价值。
  1. 首页
  2. 研发说
  3. 正文

echarts.js多图表数据展示使用小结

2016年3月24日 14241点热度 0人点赞 0条评论

echarts api文档:

http://echarts.baidu.com/echarts2/doc/doc.html

echarts demo示例:

http://echarts.baidu.com/echarts2/doc/example.html

echarts 使用五部曲:

1. 制作一个图表容器

<div id="main" style="height:400px;"></div>

2. 引入echarts.js文件

<script src="http://echarts.baidu.com/build/dist/echarts.js"></script>

3. 配置图表路径

require.config({
paths:{echarts:".../dist"
theme: '../echarts/src/theme/',
}
});

4. 加载图表js文件(模块化加载)

require(["echarts",'theme/blue', "echarts/chart/bar"], loadEchart);

5. 绘制图表

function loadEchart(ec,theme) {
var myChart = ec.init(document.getElementById("main"),theme);
var option = { ... }; // 图表配置信息
myChart.setOption(option);
}

参数theme是指定主题,主题需要在第四步引入需要加载的主题。

echarts 同页面多图表使用实例:

echart

<script src="http://localhost/beyondsoft/static/component/echarts/build/dist/echarts.js"></script>
<script type="text/javascript">
// 路径配置
require.config({
paths: {
echarts: 'http://localhost/beyondsoft/static/component/echarts/build/dist/',
theme: 'http://localhost/beyondsoft/static/component/echarts/src/theme/',
theme2: 'http://localhost/beyondsoft/static/component/echarts/src/theme/'
}
});
// 使用
require(
[
'echarts',
'theme/blue',
'echarts/chart/bar', // 使用柱状图就加载bar模块,按需加载
'echarts/chart/line'
],
function(ec,theme) {
// 基于准备好的dom,初始化echarts图表
var myChart = ec.init(document.getElementById( "main"),theme);
// 过渡---------------------
/*myChart.showLoading({
text: '正在努力的读取数据中...', //loading话术
});*/
var option = {
title: {
text: '性能概况',
subtext: 'CPU占用'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['启动时间']
},
toolbox: {
show: true
},
calculable: true,
xAxis: [{
type: 'category',
data: ['1秒', '2秒', '3秒', '4秒', '5秒', '6秒', '7秒', '8秒', '9秒', '10秒', '11秒', '12秒','13秒', '14秒', '15秒','16秒', '17秒', '18秒','19秒', '20秒', '21秒', '22秒', '23秒', '24秒', '25秒', '26秒', '27秒', '28秒', '29秒', '30秒']
}],
yAxis: [{
type: 'value'
}],
series: [{
name: '启动时间',
type: 'bar',
data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3,2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
markPoint: {
data: [{
type: 'max',
name: '最大值'
}, {
type: 'min',
name: '最小值'
}]
},
}]
};

// 为echarts对象加载数据
myChart.setOption(option);
}
);
// 使用
require(
[
'echarts',
'theme2/green',
'echarts/chart/bar', // 使用柱状图就加载bar模块,按需加载
'echarts/chart/line'
],
function(ec2,theme2) {
// 基于准备好的dom,初始化echarts图表
var myChart = ec2.init(document.getElementById( "main2"),theme2);
// 过渡---------------------
/*myChart.showLoading({
text: '正在努力的读取数据中...', //loading话术
});*/
var option = {
title: {
text: '性能概况',
subtext: 'CPU占用'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['启动时间']
},
toolbox: {
show: true
},
calculable: true,
xAxis: [{
type: 'category',
data: ['1秒', '2秒', '3秒', '4秒', '5秒', '6秒', '7秒', '8秒', '9秒', '10秒', '11秒', '12秒','13秒', '14秒', '15秒','16秒', '17秒', '18秒','19秒', '20秒', '21秒', '22秒', '23秒', '24秒', '25秒', '26秒', '27秒', '28秒', '29秒', '30秒']
}],
yAxis: [{
type: 'value'
}],
series: [{
name: '启动时间',
type: 'bar',
data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3,2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
markPoint: {
data: [{
type: 'max',
name: '最大值'
}, {
type: 'min',
name: '最小值'
}]
},
}]
};

// 为echarts对象加载数据
myChart.setOption(option);
}

);
</script>

标签: js库
最后更新:2025年9月13日

cywcd

我始终相信,技术不仅是解决问题的工具,更是推动思维进化和创造价值的方式。从研发到架构,追求极致效能;在随笔中沉淀思考,于 AI 中对话未来。

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

cywcd

我始终相信,技术不仅是解决问题的工具,更是推动思维进化和创造价值的方式。从研发到架构,追求极致效能;在随笔中沉淀思考,于 AI 中对话未来。

最新 热点 随机
最新 热点 随机
OWASP 正式发布 2026 大模型安全 Top 10 与首个“智能体控制标准”ACS Google 突发 Gemini 3.8 Flash 与安全专精模型,轻量级 AI 凭什么越级反杀? Token 账单暴跌 60%!别再给 Agent 喂垃圾日志了,手把手打造高信噪比工具过滤层 一条命令把闲置 PC 变全能 AI 服务器,开源神器 ODS 彻底火了 给 Cursor 和 Claude Code 装上这套技能库,编程 Agent 秒变“AI 科学家” Claude Desktop 正式支持 Ollama:本地零成本运行 Qwen、DeepSeek 与 Kimi 全攻略
PhotoGIMP这款免费开源设计修图神器凭什么降维打击?别再用ChatGPT死记硬背了!港大开源DeepTutor:给每个人配专属私教别再当傻白甜了!狂砸2.5万亿的2026 AI狂欢,普通人和企业到底怎么苟住?告别设计AI 泥浆:拿捏大模型“设计品味”的硬核指南DeepSeek开源Harness深度拆解:当大模型穿上“动力骨骼”,Claude Code迎来最强劲敌?用VideoLingo做全自动视频翻译,一键搞定Netflix分级字幕与自然配音
拒绝每人每月30刀!CopilotKit祭出OpenTag,把Claude在Slack上开源了 前端页面表格控件handsontable在vue项目中的应用 用 serve 替代 http-server:提升本地调试生产包的研发效能 移动端ios:active伪类无效的兼容解决方案 GPT-5.6全家桶突袭:Codex没退隐,竟与ChatGPT work合体! 用VideoLingo做全自动视频翻译,一键搞定Netflix分级字幕与自然配音
最近评论
渔夫 发布于 10 个月前(11月05日) 学到了,感谢博主分享
沙拉小王子 发布于 9 年前(11月30日) 适合vue入门者学习,赞一个
沙拉小王子 发布于 9 年前(11月30日) 适合vue入门者学习,赞一个
cywcd 发布于 9 年前(04月27日) 请参考一下这篇文章http://www.jianshu.com/p/fa4460e75cd8
cywcd 发布于 9 年前(04月27日) 请参考一下这篇文章http://www.jianshu.com/p/fa4460e75cd8

COPYRIGHT © 2025 蓝戒博客_智构苍穹-专注于大前端领域技术生态. ALL RIGHTS RESERVED.

京ICP备12026697号-2