Toggle navigation
动态上升柱状图
By
残雪X无痕
2019-04-17 06:23:06
脚本
16
21
作品使用的第三方脚本
数据管理
上传数据
支持小于 5M 任意格式(csv, xlsx, json, xml, ...)的数据文件
上传后可以通过生成的文件链接异步获取托管的数据。
历史数据
0 条
无历史数据
代码修改记录
信息提示
保存作品
对当前截图不满意?你还可以
上传本地截图
重新截图
作品名称
作品描述
标签
geo
grid
legend
markLine
markPoint
bar
effectScatter
line
lines
map
timeline
title
toolbox
tooltip
visualMap
作品默认版本
最新
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
20:11:45
图表已生成
整理代码
刷新
代码
var data = [{ product: '111', "今年": 800, "去年": 158 }, { product: '222', "今年": 200, "去年": 951 }, { product: '333', "今年": 600, "去年": 528 }, { product: '444', "今年": 500, "去年": 561 }, { product: '555', "今年": 400, "去年": 111 }, ] option = { color: ['#3398DB'], tooltip: { trigger: 'axis', textStyle: { color: "white", }, axisPointer: { // 坐标轴指示器,坐标轴触发有效 type: 'shadow' // 默认为直线,可选为:'line' | 'shadow' }, formatter: function(params) { var name = params[0].name; var info = [] params.forEach(element => { info.push({ seriesName: element.seriesName, value: element.value, marker: element.marker }) }); return ` ${name} ${info[1].marker}${info[0].seriesName}:${info[0].value + info[1].value} ${info[3].marker}${info[2].seriesName}:${info[2].value + info[3].value} `; }, }, grid: { left: '0%', right: '0%', bottom: '0%', containLabel: true }, xAxis: { type: 'category', axisLabel: { // 文字样式 color: 'black', }, data: data.map((element) => { return element.product }) }, yAxis: { type: 'value', axisLabel: { color: 'black', }, splitLine: { //分隔线颜色 lineStyle: { color: ['#162b5f'] } } }, series: [{ name: '今年', type: 'bar', stack: 'this', barWidth: 30, itemStyle: { color: new echarts.graphic.LinearGradient( 0, 0, 0, 1, [{ offset: 0, color: '#44f0ff' }, { offset: 1, color: '#3487da' } ] ) }, animationDelay: 0, //动画延迟时间 animationDuration: 0, //动画时长 animationDurationUpdate: 0 }, { name: '今年Bg', type: 'bar', stack: 'this', barWidth: 30, itemStyle: { color: '#44f0ff', opacity: 0.5 }, animationDelay: 0, //动画延迟时间 animationDuration: 0, //动画时长 animationDurationUpdate: 0 }, { name: '去年', type: 'bar', stack: 'last', barWidth: 30, itemStyle: { color: new echarts.graphic.LinearGradient( 0, 0, 0, 1, [{ offset: 0, color: '#fb387e' }, { offset: 1, color: '#3586da' } ] ) }, animationDelay: 0, //动画延迟时间 animationDuration: 0, //动画时长 animationDurationUpdate: 0 }, { name: '去年Bg', type: 'bar', stack: 'last', barWidth: 30, itemStyle: { color: '#fb387e', opacity: 0.5 }, animationDelay: 0, //动画延迟时间 animationDuration: 0, //动画时长 animationDurationUpdate: 0 }, ] }; riseAnimation(data, myChart, option, 5, 50) function riseAnimation(data, chart, option, time, speed) { var thisYearData = { norm: data.map((e) => { return e["今年"] }), data1: new Array(5).fill(0), data2: [], } var lastYearData = { norm: data.map((e) => { return e["去年"] }), data1: new Array(5).fill(0), data2: [], } chart.myOption = option chart.thisYearData = thisYearData chart.lastYearData = lastYearData function formData(data) { var norm = data.norm var data1 = data.data1 var data2 = data.data2 data2 = norm.map((e, index) => { var item = e / ((time * 1000) / speed) data1[index] += item if (data1[index] >= e) { data1[index] = 0 } return e - data1[index] }) return [data1, data2] } setInterval(function() { var thisYear = formData(this.thisYearData) var lastYear = formData(this.lastYearData) this.myOption.series[0].data = thisYear[0] this.myOption.series[1].data = thisYear[1] this.myOption.series[2].data = lastYear[0] this.myOption.series[3].data = lastYear[1] this.setOption(this.myOption) }.bind(chart), speed) }