echarts版本折线图

时间:2023-03-09 04:32:04
echarts版本折线图

1.效果如下:

echarts版本折线图        绘制折线图,应该算是说echarts中使用最简单也算使用频率最高的一种功能了吧。根据官网列子能找出规律,只是有些属性对于初接触者来说,会有点陌生,不过仔细阅读一下还是不难找出窍门滴~~~

完整代码(仅供参考):

 <!DOCTYPE html>
<html> <head>
<meta charset="utf-8">
<title>折线图</title> <script src="/static/js/jquery.min.js"></script>
<!-- 引入 echarts.js -->
<script src="/static/js/echarts/echarts.js"></script>
</head> <body>
<!-- 点击框 -->
<div onclick="clickme()" id="maindiv" style="border:1px solid #666;background-color: #ff55ff;width:100px;height:100px;">
<p>click me !!!</p>
</div>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
<div id="main" style="width: 100%;height:1000px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
function clickme(){
//隐藏掉点击框
$('#maindiv').css('display','none');
// 指定图表的配置项和数据
var option = {
backgroundColor: '#394056',
title: {
text: '手机销量折线图',
left: 'center', //grid 组件离容器左侧的距离
textStyle: {
fontWeight: '400',
fontSize: 25,
color: '#fff'
},
},
tooltip: {
trigger: 'axis',
axisPointer: {
lineStyle: {
color: '#57617B'
}
}
},
legend: {
icon: 'rect',
itemWidth: 14,
itemHeight: 5,
itemGap: 13,
//legend中的data的值需要跟series中的name保持一致,否则不会出现右上角的提示
data: ['华为手机销量','一加手机销量'],
right: '4%',
textStyle: {
fontSize: 12,
color: '#F1F1F3'
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [{
type: 'category',
boundaryGap: false,
axisLine: {
lineStyle: {
color: '#57617B'
}
},
data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
}],
yAxis: [{
type: 'value',
axisTick: {
show: false
},
axisLine: {
lineStyle: {
color: '#57617B'
}
},
axisLabel: {
margin: 10,
textStyle: {
fontSize: 14
}
},
splitLine: {
lineStyle: {
color: '#57617B'
}
}
}],
series: [{
name: '华为手机销量',
type: 'line',
smooth: true,
lineStyle: {
normal: {
width: 1
}
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: 'rgba(219, 50, 51, 0.3)'
}, {
offset: 0.8,
color: 'rgba(219, 50, 51, 0)'
}], false),
shadowColor: 'rgba(0, 0, 0, 0.1)',
shadowBlur: 10
}
},
itemStyle: {
normal: {
color: 'rgb(219,50,51)'
}
},
data: [100,200,300,400,500,230,456,485,455,789,878,122]
}, {
name: '一加手机销量',
type: 'line',
smooth: true,
lineStyle: {
normal: {
width: 1
}
},
areaStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
offset: 0,
color: 'rgba(0, 136, 212, 0.3)'
}, {
offset: 0.8,
color: 'rgba(0, 136, 212, 0)'
}], false),
shadowColor: 'rgba(0, 0, 0, 0.1)',
shadowBlur: 10
}
},
itemStyle: {
normal: {
color: 'rgb(0,136,212)'
}
},
data: [456,789,155,455,664,744,122,366,856,666,111,323]
}, ]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
}
</script>
</body> </html>

耐心、耐心……

echarts版本折线图