Echars折线配置详解
比如做成如下效果图:

所有的配置如下:
var option = {tooltip: {  // 提示框trigger: 'axis',  // 触发类型(坐标轴触发)alwaysShowContent: false, // 是否永远显示提示框的内容backgroundColor: 'rgba(32, 174, 252, 0.7)', // 提示框的背景颜色textStyle: {  // 提示框浮层的文本样式}},calculable: true,// x轴设置xAxis: [{type: 'category',name: '(月)',   // x轴名称单位nameLocation: 'end', // 名称的位置nameTextStyle: {  // 名称的样式color: '#999',fontSize: '12px'},nameGap: 0, // 名称与X轴的距离boundaryGap: true, // 坐标的刻度是否在中间min: '3',  // 坐标轴刻度的最小值max: '12',  // 坐标轴刻度的最大值axisLine: {   // 坐标轴线条相关设置(颜色等)lineStyle: {color: '#ccc'}},axisTick: {  // 坐标轴刻度相关设置length: '0'  // 长度设置为0},axisLabel: {  // 坐标轴刻度标签margin: 7,  // 刻度标签与轴线之间的距离textStyle: {color: '#999',  // 坐标轴刻度文字的颜色fontSize: '12px'  // 坐标轴刻度文字的大小},// rotate: 30 // 旋转30度},data: ['3', '4', '5', '7', '8', '12'],// show: false}], // y轴设置yAxis: [    {type: 'value',  // 类型数值轴name: '(人)',   // Y轴名称单位nameTextStyle: {  // 名称的样式color: '#999',fontSize: '12px'},nameGap: 13, // 名称与Y轴的距离axisTick: {  // 坐标轴相关设置length: '0'},axisLine: {  // 坐标轴线条相关设置(颜色等)lineStyle: {color: '#ccc'}},axisLabel: {  // 坐标轴标签相关设置,距离颜色等margin: 7,  // 刻度标签与轴线之间的距离// formatter: '{value} C',  // 标签内容内置的格式转化器在后面加一个单位值textStyle: {color: '#999',  // 坐标轴刻度文字的颜色fontSize: '12px'  // 坐标轴刻度文字的大小}},splitLine: {  // 坐标轴分割线。默认数值轴显示,类目轴不显示show: false}}],grid: { // 直角坐标系内绘图网格left: 36  },series: [  // 系列列表{name: '人',  // 系列名称,用于tooltip的显示type: 'line',data: [2, 2, 2, 2, 2, 7, 2],itemStyle: {  // 折线拐点的样式normal: {color: '#20aefc'  // 拐线拐点的颜色}},lineStyle: {  // 线条的样式normal: {color: '#20aefc',  // 折线的颜色}},smooth: 0.3, // 是否平滑处理,如果是Number类型(取值范围为0到1),表示平滑程度,越小越接近折线段,反之areaStyle: {  // 区域填充的样式normal: {// 线性渐变color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0, color: '#b1e3fe'  // 0% 处的颜色}, {offset: 1, color: '#fff' // 100% 处的颜色}], false)}},markPoint: {  // 图标标注data: [{type: 'max', name: '最大值'},{type: 'min', name: '最小值'}]},markLine: {data: [{type: 'average', name: '平均值'}]}},{name: '人',  // 系列名称,用于tooltip的显示type: 'line',data: [6, 6, 6, 6, 6, 6, 6],itemStyle: {  // 折线拐点的样式normal: {color: '#20aefc'  // 拐线拐点的颜色}},// smooth: 0.3, // 是否平滑处理,如果是Number类型(取值范围为0到1),表示平滑程度,越小越接近折线段,反之lineStyle: {  // 线条的样式normal: {color: '#20aefc',  // 折线的颜色}},areaStyle: {  // 区域填充的样式normal: {// 线性渐变color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0, color: '#b1e3fe'  // 0% 处的颜色}, {offset: 1, color: '#fff' // 100% 处的颜色}], false)}},markPoint: {  // 图标标注data: [{type: 'max', name: '最大值'},{type: 'min', name: '最小值'}]},markLine: {data: [{type: 'average', name: '平均值'}]}},{name: '人',  // 系列名称,用于tooltip的显示type: 'line',data: [10, 10, 10, 10, 10, 10, 10],itemStyle: {  // 折线拐点的样式normal: {color: '#20aefc'  // 拐线拐点的颜色}},lineStyle: {  // 线条的样式normal: {color: '#20aefc',  // 折线的颜色}},areaStyle: {  // 区域填充的样式normal: {// 线性渐变color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0, color: '#b1e3fe'  // 0% 处的颜色}, {offset: 1, color: '#fff' // 100% 处的颜色}], false)}},markPoint: {  // 图标标注data: [{type: 'max', name: '最大值'},{type: 'min', name: '最小值'}]},markLine: {data: [{type: 'average', name: '平均值'}]}}]
};HTML代码:
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><title>ECharts</title><!-- 引入 echarts.js --><script src="./echarts4.x.js"></script><script type="text/javascript" src="./zhexian.js"></script>
</head>
<body><!-- 为ECharts准备一个具备大小(宽高)的Dom --><div id="main" style="width: 400px;height:400px;margin: 0 auto"></div><script type="text/javascript">// 基于准备好的dom,初始化echarts实例var myChart = echarts.init(document.getElementById('main'));// 使用刚指定的配置项和数据显示图表。myChart.setOption(option);</script>
</body>
</html>转载自:https://www.cnblogs.com/tugenhua0707/p/9380352.html