蓝戒博客

  • 首页
  • 研发说
  • 架构论
  • 效能录
  • AI谈
  • 随笔集
智构苍穹
AI为翼,架构为骨,文化为魂,实践探新境,价值筑长青。
  1. 首页
  2. 研发说
  3. 正文

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

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

最新 热点 随机
最新 热点 随机
npm 安全更新:把握令牌变更与发布体系的迁移参考指南 TresJS:用 Vue 构建现代化交互式 3D 体验 i18n 高效实现方案:前端国际化神器安利一波 前端国际化 i18n 实践:从项目到组件库的全链路方案 GEO(生成引擎优化)完整指南:AI 搜索时代的企业内容新机会 NativeScript:用 JavaScript / TypeScript 构建真正的原生应用
前端开源工具 PinMe:极简部署体验分享大屏适配的核心痛点与一行 autofit 解决方案markdown-exit:现代化的 Markdown 解析工具Lerna + Monorepo:前端多仓库管理的最佳实践CrewAI:基于角色协作的 AI Agent 团队框架浅析2025 最推荐的 uni-app 技术栈:unibest + uView Pro 高效开发全攻略
flutter系列之开发模拟器debug 深入全面理解JavaScript的执行上下文 【视频】乔布斯:遗失的访谈(1995) intro.js网站页面使用分步引导插件 html5.js让所有IE支持HTML5元素 package.json配置字段全解析
最近评论
渔夫 发布于 1 个月前(11月05日) 学到了,感谢博主分享
沙拉小王子 发布于 8 年前(11月30日) 适合vue入门者学习,赞一个
沙拉小王子 发布于 8 年前(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