基本配置项
// 图表标题
title: {
x: 'left', // 水平安放位置,默认为左对齐,可选为:
'center' ¦ 'left' ¦ 'right'
//{number}(x坐标,单位px)
y: 'top', // 垂直安放位置,默认为全图顶端,可选为:
'top' ¦ 'bottom' ¦ 'center'
textStyle: {
fontSize: 18,
fontWeight: 'bolder',
color: '#333' // 主标题文字颜色
},
},
//图例
legend{
orient: 'horizontal', //布局方式,默认为水平布局,可选为:
'horizontal' (水平)¦ 'vertical'(垂直)
x: 'center', // 可以写为'number'(支持使用百分比)//水平安放位置,默认为全图居中,可选为:
'center' ¦ 'left' ¦ 'right'
y: 'top', //可以写为'number'(支持使用百分比)//垂直安放位置,默认为全图顶端,可选为:
'top' ¦ 'bottom' ¦ 'center'
borderWidth: 0, // 图例边框线宽,单位px,默认为0(无边框)
padding: 5, // 图例内边距,单位px,默认各方向内边距为5,
textStyle: {
color: '#333' // 图例文字颜色
}
}
// 提示框
tooltip: {
trigger: 'item', // 可选为:'item'(散点图,饼状图 )¦ 'axis'(折线图,柱状图)
borderRadius: 4, // 提示边框圆角,单位px,默认为4
borderWidth: 0,// 提示边框线宽,单位px,默认为0(无边框)
padding: 5, // 提示内边距,单位px,默认各方向内边距为5
textStyle: {
color: '#000' //提示框文字颜色
}
}
//折线图 line
option = {
itemStyle: { //折线的样式
normal: { //初始化
lineStyle: {
width: 2,
type: 'solid',
shadowColor : 'rgba(0,0,0,0)',
label: { //图形上的文本标签,可用于说明图形的一些数据信息,比如值,名称等
show: false
}
}
},
emphasis: { //悬浮时
// color: 各异,
label: {
show: false
}
}
},
series: [{
name: '成交',
type: 'line', //类型:折线图
stack: true, //是否堆叠(可放多条折线)
smooth:true, //折线平滑度,默认为0,取值范围为0-1
data: [10, 12, 21, 54, 260] //数据
},
{
name: '预购',
type: 'line',
smooth: true,
data: [30, 182, 434, 791, 1]
}]
symbolSize: 2, // 拐点图形大小
},
//柱状图 bar
var optionstyle ={//把样式提取出来可以重复使用
itemStyle: {
normal: {
// color: '各异',
barBorderColor: '#fff', // 柱条边线
barBorderRadius: 0, // 柱条边线圆角,单位px,默认为0
barBorderWidth: 1, // 柱条边线线宽,单位px,默认为1
label: {
show: false
}
},
emphasis: {
barBorderColor: 'rgba(0,0,0,0)', // 柱条边线
barBorderRadius: 0, // 柱条边线圆角,单位px,默认为0
barBorderWidth: 1, // 柱条边线线宽,单位px,默认为1
label: {
show: false
}
}
},
}
option = {
xAxis: [
{
type: 'category',
axisTick: {show: false},
itemStyle:optionstyle;//引用封装好的样式
data: ['2012', '2013', '2014', '2015', '2016']
}
],
yAxis: [
{
type: 'value'//不需设值,echarts会根据series的data动态设置
}
],
series: [{
name: 'Forest',
type: 'bar',
barWidth:'20', //柱形条宽度
barGap: '30%', // 柱间距离,默认为柱形宽度的30%,可设固定值
barCategoryGap : '20%', // 类目间柱形距离,默认为类目间距的20%,可设固定值
showBackground: true,//柱形条背景色
backgroundStyle: {
color: 'rgba(220, 220, 220, 0.8)'
},
stack: true, //是否堆叠(可放多条折线)
data: [320, 332, 301, 334, 390]
}]
}
// 饼图 pie
option = {
center : ['50%', '50%'], // 默认全局居中
radius : [0, '75%'],
selectedOffset: 10, // 选中时扇区偏移量
label: { //图表对应的提示文字
show: false,
position: 'center'
},
itemStyle: {
labelLine: { //视觉引导线(悬浮时连接图表和提示文字的线)
show: false,
smooth:0,//弯曲程度
length: 20,//没有length2时为直线
length2: 100,//有length2时为折线
lineStyle: {
width: 1,
type: 'solid',
color:'任意'
}
}
}
}
```
如有错误欢迎指出