echarts.js的使用
前提准备条件折线图
前提准备条件
引入echarts.js;
<script src
="./echarts.min.js"></script
>
设置一个容器,并给它 设置宽高属性; 必须给容器设置宽高,它是用来给画布提供一个空间的,如果不设置是不会显示的;
<div id
="echarts" style
="width:1000px;height:600px;"></div
>
echarts部分的js;
var myChart
= echarts
.init(document
.getElementById("echarts"));
var option
= {};
myChart
.setOption(option
);
折线图
var option
={
backgroundColor
:'#FBFBFB',
tooltip
:{
trigger
:'axis'
},
legend
:{
data
:['充值','消费']
},
calculable
:true,
toolbox
: {
show
: true,
feature
: {
dataZoom
: {
yAxisIndex
: 'none'
},
dataView
: {readOnly
: false},
magicType
: {type
: ['line', 'bar']},
restore
: {},
saveAsImage
: {}
}
},
xAxis
:[
{
axisLabel
:{
rotate
:30,
interval
:0
},
axisLine
:{
lineStyle
:{
color
:'#CECECE'
}
},
type
:'category',
boundaryGap
:false,
data
: function (){
var list
= [];
for (var i
= 10; i
< 18; i
++) {
if(i
<= 12){
list
.push('2016-'+i
+ '-01');
}else{
list
.push('2017-'+(i
-12) + '-01');
}
}
return list
;
}()
}
],
yAxis
:[
{
type
:'value',
axisLine
:{
lineStyle
:{
color
:'#CECECE'
}
}
}
],
series
:[
{
name
:'充值',
type
:'line',
symbol
:'none',
color
:['#66AEDE'],
itemStyle
:{
normal
:{
label
:{show
:true}
}
},
data
:[800, 300, 500, 800, 300, 600,500,600],
markPoint
: {
data
: [
{type
: 'max', name
: '最大值'},
{type
: 'min', name
: '最小值'}
]
},
markLine
: {
data
: [
{type
: 'average', name
: '平均值'}
]
}
},
{
name
:'消费',
type
:'line',
symbol
:'triangle',
smooth
:0.4,
color
:['#90EC7D'],
itemStyle
:{
normal
:{
label
:{show
:true,color
:'white',backgroundColor
:'black'}
}
},
data
:[600, 300, 400, 200, 300, 300,200,400]
}
]
};
绘制折线图如下所示:
转载请注明原文地址: https://lol.8miu.com/read-5906.html