
按需引入
import * as echarts from 'echarts/core';import { GridComponent } from 'echarts/components';import { BarChart, LinesChart } from 'echarts/charts';import { CanvasRenderer } from 'echarts/renderers';echarts.use([GridComponent, BarChart, LinesChart, CanvasRenderer]);var chartDom = document.getElementById('main');var myChart = echarts.init(chartDom);var option;// option && myChart.setOption(option);
options
const option = {backgroundColor: '#222',stack: true,grid: { bottom: 0, top: 0, left: 0, right: 0 },xAxis: {data: [],silent: true,splitLine: { show: false },axisLine: { show: false }},yAxis: {silent: true,splitLine: { show: false },axisLine: { show: false },axisTick: { show: false },axisLabel: { show: false }},series: [{type: 'bar',data: [200, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 0, 37, 37, 37, 35, 35, 35,37, 37, 37, 22, 23, 24, 25, 26, 25, 24, 23, 22, 0, 33, 33, 33, 31, 31,31, 33, 33, 33, 19, 19, 19, 21, 37, 21, 19, 19, 19, 53, 53, 53, 51, 51,51, 53, 53, 53, 35, 35, 35, 35, 35, 35, 35, 19, 18.5, 18, 17.5, 17,16.5, 16, 16, 16, 16, 16, 33, 33, 33, 35, 35, 35, 33, 33, 33, 0, 43, 43,43, 43, 43, 43, 43, 10, 10, 10, 10, 10, 6, 6, 6, 0, 38, 39, 40, 41, 42,41, 40, 39, 38, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 0, 38, 39, 40,41, 42, 43, 43, 43, 43, 43],itemStyle: { normal: { color: 'rgb(38, 41, 57)' } }},{type: 'bar',data: [180, 25, 25, 25, 27, 43, 27, 25, 25, 25, 0, 39, 2, 2, 4, 22, 6, 4, 2, 2,0, 2, 1, 24, 24, 24, 20, 20, 20, 0, 73, 40, 40, 40, 42, 41, 40, 37, 36,35, 0, 60.3, 61, 59.599999999999994, 44.5, 61, 63.5, 63.599999999999994,63.7, 29.700000000000003, 29.599999999999994, 29.5, 31, 30.5,29.599999999999994, 27, 26.299999999999997, 0, 4, 4, 4, 6, 6, 6, 4, 4,4, 0, 60.5, 62, 63.5, 65, 66, 67, 68, 69, 53, 54, 65, 64, 65, 66, 69,68, 67, 99, 55, 6, 6, 6, 8, 24, 8, 6, 6, 6, 0, 89, 93, 93, 93, 99, 57,56, 55, 3, 2, 3, 6, 7, 8, 44, 44, 44, 28, 29, 30, 33, 34, 35, 34, 79,41, 0, 32, 33, 34, 35, 36, 37, 37, 37, 37, 37, 51, 51, 51, 53, 53, 53,51, 51, 51, 0],itemStyle: { normal: { color: 'rgb(28, 31, 47)' } }},{coordinateSystem: 'cartesian2d',type: 'lines',zlevel: 2,symbolSize: 3,effect: {show: true,period: 1,trailLength: 0.01,symbolSize: 5,symbol: 'pin',loop: true},lineStyle: {normal: { color: '#BF3EFF', opacity: 0.6, curveness: 0.1, width: 0.01 }},data: [{coords: [[40, 166],[40, 210]]},{coords: [[41, 165],[65, 165]]},{coords: [[39, 165],[15, 165]]},{coords: [[40, 164],[40, 115]]},{coords: [[40, 164],[55, 192]]},{coords: [[40, 164],[56, 175]],lineStyle: { normal: { color: '#FFFFFF' } }},{coords: [[40, 164],[46, 197]],lineStyle: { normal: { color: '#FFFFFF' } }},{coords: [[41, 190],[47, 215]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[48, 190],[57, 205]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[52, 180],[62, 185]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[55, 170],[68, 171]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[39, 166],[24, 190]]},{coords: [[40, 164],[24, 175]],lineStyle: { normal: { color: '#FFFFFF' } }},{coords: [[40, 164],[31, 195]],lineStyle: { normal: { color: '#FFFFFF' } }},{coords: [[25, 168],[13, 176]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[29, 175],[18, 195]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[33, 179],[24, 210]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[36, 185],[35, 210]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[40, 164],[26, 137]]},{coords: [[40, 164],[34, 135]],lineStyle: { normal: { color: '#FFFFFF' } }},{coords: [[40, 164],[25, 153]],lineStyle: { normal: { color: '#FFFFFF' } }},{coords: [[39, 144],[36, 120]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[34, 144],[22, 123]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[30, 151],[21, 143]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[30, 159],[18, 157]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[40, 164],[55, 135]]},{coords: [[40, 164],[55, 152]],lineStyle: { normal: { color: '#FFFFFF' } }},{coords: [[40, 164],[46, 135]],lineStyle: { normal: { color: '#FFFFFF' } }},{coords: [[52, 160],[65, 153]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[52, 150],[62, 133]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[47, 144],[53, 123]],lineStyle: { normal: { color: '#00FF33' } }},{coords: [[43, 134],[45, 113]],lineStyle: { normal: { color: '#00FF33' } }}],animationDelay: 1100},{coordinateSystem: 'cartesian2d',type: 'lines',zlevel: -2,effect: {show: true,period: 1,trailLength: 0.01,symbolSize: 12,symbol: 'circle',loop: true},lineStyle: { normal: { color: '#ccc', opacity: 0, curveness: 0 } },data: [{coords: [[40, 25],[40, 165]]}],animationDelay: 1100},{coordinateSystem: 'cartesian2d',type: 'lines',zlevel: -2,effect: {show: true,period: 1,trailLength: 0.01,symbolSize: 12,symbol: 'circle',loop: true},lineStyle: { normal: { color: '#ccc', opacity: 0, curveness: 0 } },data: [{coords: [[110, 25],[110, 165]]}],animationDelay: 1100},{coordinateSystem: 'cartesian2d',type: 'lines',zlevel: 2,symbolSize: 3,effect: {show: true,period: 1,trailLength: 0.01,symbolSize: 5,symbol: 'pin',loop: true},lineStyle: {normal: { color: '#ccc', opacity: 0.02, width: 0.01, curveness: 0.1 }},data: [{coords: [[110, 166],[110, 210]]},{coords: [[111, 165],[135, 165]]},{coords: [[109, 165],[85, 165]]},{coords: [[110, 164],[110, 115]]},{coords: [[110, 164],[125, 192]]},{coords: [[110, 164],[126, 175]],lineStyle: { normal: { color: '#DD2222' } }},{coords: [[110, 164],[116, 197]],lineStyle: { normal: { color: '#DD2222' } }},{coords: [[111, 190],[117, 215]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[118, 190],[127, 205]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[122, 180],[132, 185]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[125, 170],[138, 171]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[109, 166],[94, 190]]},{coords: [[110, 164],[94, 175]],lineStyle: { normal: { color: '#DD2222' } }},{coords: [[110, 164],[101, 195]],lineStyle: { normal: { color: '#DD2222' } }},{coords: [[95, 168],[83, 176]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[99, 175],[88, 195]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[103, 179],[94, 210]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[106, 185],[105, 210]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[110, 164],[96, 137]]},{coords: [[110, 164],[104, 135]],lineStyle: { normal: { color: '#DD2222' } }},{coords: [[110, 164],[95, 153]],lineStyle: { normal: { color: '#DD2222' } }},{coords: [[109, 144],[106, 120]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[104, 144],[92, 123]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[100, 151],[91, 143]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[100, 159],[88, 157]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[110, 164],[125, 135]]},{coords: [[110, 164],[125, 152]],lineStyle: { normal: { color: '#DD2222' } }},{coords: [[110, 164],[116, 135]],lineStyle: { normal: { color: '#DD2222' } }},{coords: [[122, 160],[135, 153]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[122, 150],[132, 133]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[117, 144],[123, 123]],lineStyle: { normal: { color: '#FFFF00' } }},{coords: [[113, 134],[115, 113]],lineStyle: { normal: { color: '#FFFF00' } }}],animationDelay: 1100}],animationEasing: 'elasticOut'};
绘制月亮
function r(max) {let m = max || 10return Math.floor(Math.random() * m)}const moonAndStars = {type: 'graph',data: (function () {let moonPosition = {x: 190,y: 0.5,}let moon = [{symbolSize: 70,x: moonPosition.x,y: moonPosition.y,},{symbolSize: 60,x: moonPosition.x - 1.5,y: moonPosition.y - 1.5,itemStyle: {normal: {color: 'rgb(51, 51, 51)',},},},{symbolSize: 0,x: 0,y: 0,},{symbolSize: 0,x: 200,y: 100,},]let num = 100let stars = []for (let i = 0; i < num; i++) {stars.push({symbolSize: r(3),x: r(200),y: r(50),})}return moon.concat(stars)})(),itemStyle: {normal: {color: '#ccc',},},silent: true,z: -1,}
