解压以后在 echarts-5.2.2\dist 文件下
2. 修改echarts.js
第一处修改:
添加内容:
window.layui && layui.define ? layui.define(function(exports){exports('echarts',factory(exports))}) :
echarts.js 开头部分添加以上内容:
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
// 新增位置
window.layui && layui.define ? layui.define(function(exports){exports('echarts',factory(exports))}) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.echarts = {}));
}(this, (function (exports) { 'use strict';
第二处修改:
添加内容:
return exports;
3. html
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div class="layui-card">
<div class="layui-card-header">柱形图</div>
<div class="layui-card-body">
<div id="EchartZhu" style="width: 500px;height: 500px;"> </div>
</div>
</div>
- layui 引入js
echarts文件放在/resources/layui_ext/目录下的echarts/echarts.js,
通过extend引入模块
layui.config({base:'/resources/layui_ext/'}).extend({ echarts: 'echarts/echarts'}).use(['jquery', 'form', 'layer', 'table','upload', 'element', 'echarts', 'carousel'], function () {
var $ = layui.jquery;
var element = layui.element;
carousel = layui.carousel;
echarts = layui.echarts;
var chartZhu = echarts.init(document.getElementById('EchartZhu'));
//指定图表配置项和数据
var optionchart = {
title: {
text: '商品订单'
},
tooltip: {},
legend: {
data: ['销量']
},
xAxis: {
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周天']
},
yAxis: {
type: 'value'
},
series: [{
name: '销量',
type: 'bar', //柱状
data: [100,200,300,400,500,600,700],
itemStyle: {
normal: { //柱子颜色
color: 'red'
}
},
},{
name:'产量',
type:'bar',
data:[120,210,340,430,550,680,720],
itemStyle:{
normal:{
color:'blue'
}
}
}]
};
var optionchartZhe = {
title: {
text: '商品订单'
},
tooltip: {},
legend: { //顶部显示 与series中的数据类型的name一致
data: ['销量', '产量', '营业额', '单价']
},
xAxis: {
// type: 'category',
// boundaryGap: false, //从起点开始
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
},
yAxis: {
type: 'value'
},
series: [{
name: '销量',
type: 'line', //线性
data: [145, 230, 701, 734, 1090, 1130, 1120],
}, {
name: '产量',
type: 'line', //线性
data: [720, 832, 801, 834, 1190, 1230, 1220],
}, {
smooth: true, //曲线 默认折线
name: '营业额',
type: 'line', //线性
data: [820, 932, 901, 934, 1290, 1330, 1320],
}, {
smooth: true, //曲线
name: '单价',
type: 'line', //线性
data: [220, 332, 401, 534, 690, 730, 820],
}]
};
var optionchartBing = {
title: {
text: '商品订单',
subtext: '纯属虚构', //副标题
x: 'center' //标题居中
},
tooltip: {
// trigger: 'item' //悬浮显示对比
},
legend: {
orient: 'vertical', //类型垂直,默认水平
left: 'left', //类型区分在左 默认居中
data: ['单价', '总价', '销量', '产量']
},
series: [{
type: 'pie', //饼状
radius: '60%', //圆的大小
center: ['50%', '50%'], //居中
data: [{
value: 335,
name: '单价'
},
{
value: 310,
name: '总价'
},
{
value: 234,
name: '销量'
},
{
value: 135,
name: '产量'
}
]
}]
};
chartZhu.setOption(optionchart, true);
});