蓝戒博客

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

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

2016年3月24日 13985点热度 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 中对话未来。

最新 热点 随机
最新 热点 随机
Gemma 4发布4天即遭"完全越狱",开源AI的安全与自由之争 一个文件让AI写代码不再"翻车":45K星的Karpathy指南火了 3秒克隆你的声音,30国语言自由切换!这款2B开源语音模型,正在重新定义AI配音 claude-mem:给 Claude Code 补上一块最关键的“长期记忆” 🔥 狂揽 51.5k Star!这款名为 GSD 的神器,专治 AI 写代码"越写幻觉越严重" Token 节省的神器 RTK:降 90%,适用 Claude Code、Codex、Cursor 等
Dan Koe:不想打工?用这套方法把兴趣变成收入开源AI 搜索代理 MiroThinker 1.7:当大家还在卷参数,它已经开始卷“查证能力”了停止无效努力:Dan Koe 深度长文,极致专注力,一套让你进入心流的终极方法论2026 AI 智能体革命:LangGraph 如何让你一个人活成一支队伍?AI 智能体爆发:从会生成到会行动,2026 年普通人如何抓住 AaaS 变现红利AI专用浏览器来了:比Chrome快10倍,Agent时代的基础设施正在重构
Html2canvas实现网页截图应用 js判断浏览器类型并区分IE不同版本 UniApp 从入门到实战:一套代码多端运行的最佳实践 Monaco Editor真香,从对比到实战封装,一篇讲透 在线考试防作弊js实现代码完整版 前端高性能工具链新选择:Oxlint & Oxfmt 深度分享
最近评论
渔夫 发布于 5 个月前(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