蓝戒博客

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

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

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

最新 热点 随机
最新 热点 随机
Vue 3.6「无虚拟 DOM」时代开启:深入解读 Vapor Mode 的革命性变革 2025 最推荐的 uni-app 技术栈:unibest + uView Pro 高效开发全攻略 前端开源工具 PinMe:极简部署体验分享 架构评估方法 ATAM:系统性洞察架构质量的利器 软件系统架构评估与质量属性分析 AI 大模型开发:如何实现数据向量化
Webpack 实战:Code Splitting 优化页面加载性能前端开源工具 PinMe:极简部署体验分享AI 产品前端技术全解析:模型可视化与流式响应实践前端内存泄露防范及编码攻略DApp开发前端技术全解析:技术选型、功能实现与开发步骤Web Workers:释放浏览器多线程的魔力
Html2canvas实现网页截图应用 互联网思维下,产品的17项关键要素 原生js写ajax请求(兼容各主流浏览器) css渐变背景色完美兼容解决方案 《WebKit 技术内幕》前端开发者必读的浏览器内核知识 网站公共底文件在不同高度页面下显示位置解决方案
最近评论
渔夫 发布于 6 天前(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