1. 程式人生 > 其它 >echart實現折線圖

echart實現折線圖

技術標籤:echart的使用

效果圖
在這裡插入圖片描述
程式碼:

var mess = ["00:00", "03:00", "06:00", "09:00", "12:00", "15:00", "18:00", "21:00", "24:00"];
    var mess3 = preData;
    var mess4 = curData;
    var option = {
      legend: {
        show: true,
        itemWidth:
20, itemHeight: 10, itemGap: 10, textStyle: { fontSize: 10, color: "#ccc", }, }, tooltip: { trigger: "axis", axisPointer: { lineStyle: { color: { type: "linear"
, x: 0, y: 0, x2: 0, y2: 1, colorStops: [ { offset: 0, color: "rgba(0, 255, 233,0)", }, { offset: 0.5, color:
"rgba(255, 255, 255,1)", }, { offset: 1, color: "rgba(0, 255, 233,0)", }, ], global: false, }, }, }, }, grid: { top: "25%", left: "10%", right: "5%", bottom: "25%", }, xAxis: { data: mess, axisTick: { show: false, }, boundaryGap: false, axisLine: { show: true, lineStyle: { color: "#414965", }, }, axisLabel: { interval: 1, textStyle: { color: "#7089ba", fontSize: 12, }, margin: 10, //刻度標籤與軸線之間的距離。 }, }, yAxis: { name:unit, nameTextStyle: { color: "#fff", }, splitLine: { show: true, lineStyle: { color: "#414965", opacity: 0.3, }, }, axisTick: { show: false, }, axisLine: { show: false, }, axisLabel: { textStyle: { color: "#7089ba", fontSize: 12, }, }, splitNumber: 3 }, series: [ { name: "今日", type: "line", smooth: true, //是否平滑 showAllSymbol: false, symbol: "circle", symbolSize: 2, lineStyle: { normal: { color: "#44b6fe", }, }, itemStyle: { color: "#44b6fe", }, tooltip: { show: true, }, areaStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: "rgba(53,194,246,0.7)", }, { offset: 1, color: "rgba(53,194,246,0.1)", }, ], false ), shadowBlur: 20, }, }, data: mess4, markPoint: { symbolSize: 30, data: [ { type: "max", name: "最大值" }, { type: "min", name: "最小值" }, ], }, }, { name: "昨日", type: "line", smooth: true, //是否平滑 showAllSymbol: false, symbol: "circle", symbolSize: 2, lineStyle: { normal: { color: "#ad16ff", }, }, itemStyle: { color: "#ad16ff", }, tooltip: { show: true, }, areaStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: "rgba(179,64,242,0.7)", }, { offset: 1, color: "rgba(179,64,242,0.1)", }, ], false ), shadowColor: "rgba(179,64,242, 0)", shadowBlur: 20, }, }, data: mess3, markPoint: { symbolSize: 30, data: [ { type: "max", name: "最大值" }, { type: "min", name: "最小值" }, ], }, }, ], };