代码更新记录 V2
- var positiveColor = "green";
- var negative = "red";
- var totalColor = "blue";
- var data = option.series[0].data.map(item=>(item.value));
- var help = [];
- var positive = [];
- var negative = [];
- let total;
- for (var i = 0, sum = 0; i < data.length; ++i) {
- if (data[i] >= 0) {
- positive.push(data[i]);
- negative.push('-');
- } else {
- positive.push('-');
- negative.push(-data[i]);
- }
- if (i === 0) {
- help.push(0);
- } else {
- sum += data[i - 1];
- if (data[i] < 0) {
- help.push(sum + data[i]);
- } else {
- help.push(sum);
- }
- }
- total = sum;
- }
- let len = data.length;
- let total_array = new Array(len);
- total_array.fill(0);
- total_array.push(total);
- let series_zero = option.series[0];
- let series_first = {};
- let series_second = {};
- let series_total = {};
- Object.assign(series_first,series_zero);
- Object.assign(series_second,series_zero);
- Object.assign(series_total,series_zero);
- series_zero.data = help;
- series_first.data = positive;
- series_second.data = negative;
- series_total.data = total_array;
- console.log(`total:${total_array}`);
- option.xAxis.data.push({
- value:"总计"});
- series_zero.itemStyle = {
- normal: {
- barBorderColor: 'rgba(0,0,0,0)',
- color: 'rgba(0,0,0,0)'
- },
- emphasis: {
- barBorderColor: 'rgba(1,0,0,0)',
- color: 'rgba(0,0,0,0)'
- }
- };
-
- series_first.itemStyle = {
- color: 'green'
- }
- series_second.itemStyle = {
- color: 'red'
- }
- series_total.itemStyle = {
- color: 'blue'
- }
- series_zero.stack = 'all';
- series_first.stack = 'all';
- series_second.stack = 'all';
- series_total.stack = 'all';
- series_first.name = '上升';
- series_second.name = '下降';
- series_total.name = '总计';
- option.legend.show = true;
- option.legend.data = ["上升","下降","总计"]
- option.series = [series_zero,series_first,series_second,series_total];
- option.tooltip = {
- show: true
- }
- return option
复制代码
瀑布图V2.zip
(24.39 KB, 下载次数: 157)
|