###1.效果图
2.html代码如下
<view class="container">
<ec-canvas id="mychart-dom-line" canvas-id="mychart-line" ec="{{ ec }}"></ec-canvas>
</view>
3.json文件
{
"usingComponents": {
"ec-canvas": "../../ec-canvas/ec-canvas"
}
}
3.js代码如下
import * as echarts from '../../ec-canvas/echarts';
const app = getApp();
function initChart(canvas, width, height, dpr) {
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr
});
canvas.setChart(chart);
var option = {
title: {
text:'-对比图'
},
color: ["#8385f3", "#40beff", "#fa9d3b"],
grid: {
left: "0%",
right: "5%",
containLabel: true,
height: "60%",
},
tooltip: {
show: true,
trigger: 'axis',
axisPointer: {
type: 'cross',
axis: 'x',
}
},
legend: {
itemWidth: 20,
itemHeight: 10,
itemGap: 30,
icon:'circle',
bottom:'20',
},
xAxis: {
type: 'category',
axisTick: { show: true },
axisLine: { show: true },
splitLine:{
lineStyle:{
width:2
}
},
boundaryGap: false,
data: ['00:00', '00:30','01:00','01:30',"02:00",'02:30', '03:00','03:30','04:00','04:30','05:00','05:30', '06:00', ],
axisLabel: {
interval:5,
}
},
yAxis: {
x: 'center',
type: 'value',
splitLine: {
lineStyle: {
type: 'dashed'
}
},
scale: true,
max: 600,
min: 0,
splitNumber: 3,
show:true,
axisTick: { show: false },
axisLine: { show: false },
},
series: [{
name: '当前日', /
type: 'line',
smooth: true,
hoverAnimation:false,
symbolSize: 2,
itemStyle:{
normal:{
lineStyle:{
width:1,
}
}
},
data: [80, 360, 550, 300, 178, 240, 333,180, 360, 450, 300, 178, 240, 333,180, 360, 350, 300, ]
}, {
name: '一天前',
type: 'line',
smooth: true,
hoverAnimation:false,
symbolSize: 2,
itemStyle:{
normal:{
lineStyle:{
width:1,
}
}
},
data: [12, 150, 151, 235, 370, 430, 520,112, 150, 151, 235, 370, 430, 520,112, 150, 151]
}, {
name: '7天前',
type: 'line',
symbolSize: 2,
smooth: true,
hoverAnimation:false,
itemStyle:{
normal:{
lineStyle:{
width:1,
}
}
},
data: [20, 230, 131, 50, 440, 320, 110,120, 230, 131, 50, 440, 320, 110,120, 230, 131, 50, 440, 320, 110,120, 230, 131, 50, 440, 320, 110,120, 230, 131, 50, 440, 320, 110,120, 230, 131, 50, 440, 320, 110,120, 230, 131, 50, 440, 320,]
}]
};
chart.setOption(option);
return chart;
}
Page({
onShareAppMessage: function (res) {
return {
title: 'ECharts 可以在微信小程序中使用啦!',
path: '/pages/index/index',
success: function () { },
fail: function () { }
}
},
data: {
ec: {
onInit: initChart
}
},
onReady() {
}
});
|