找回密码
 立即注册

QQ登录

只需一步,快速开始

nimotea
超级版主   /  发表于:2024-1-30 09:37  /   查看:925  /  回复:1
效果
image.png436961669.png

拷贝代码
  1. let total_name = "总计";

  2. let num = 0;
  3. let accumulateValue = [];
  4. option.xAxis.data.reverse().push({
  5. value:total_name
  6. });
  7. option.xAxis.data.reverse();


  8. option.series[0].data.reverse().map(item=>{
  9.         accumulateValue.push(num);  
  10.         num += item.value;
  11. })
  12. accumulateValue.push(0);
  13. accumulateValue = accumulateValue.reverse();


  14. option.series[0].data.push({
  15. itemStyle : {
  16.         opacity : 1
  17. },
  18.   value:num
  19. });
  20. option.series[0].data.reverse();
  21. option.series[0].stack = 'Total';
  22. option.series= [
  23.   {
  24.       name: 'Placeholder',
  25.       type: 'bar',
  26.       stack: 'Total',
  27.       itemStyle: {
  28.         borderColor: 'transparent',
  29.         color: 'transparent'
  30.       },
  31.       emphasis: {
  32.         itemStyle: {
  33.           borderColor: 'transparent',
  34.           color: 'transparent'
  35.         }
  36.       },
  37.       data: accumulateValue

  38.   },
  39. ...option.series
  40. ];



  41. return option;
复制代码
方式1:
在Wyn管理后台的【导入】功能,导入以下Zip包,然后在仪表板设计器的左侧工具箱的【组件模板分类中】可以找到。
瀑布图.zip (428.24 KB, 下载次数: 60)

1 个回复

倒序浏览
nimotea
超级版主   /  发表于:2024-6-24 12:05:29
沙发
代码更新记录 V2
image.png187558287.png

  1. var positiveColor = "green";
  2. var negative = "red";
  3. var totalColor = "blue";

  4. var data = option.series[0].data.map(item=>(item.value));
  5. var help = [];
  6. var positive = [];
  7. var negative = [];
  8. let total;
  9. for (var i = 0, sum = 0; i < data.length; ++i) {
  10.   if (data[i] >= 0) {
  11.     positive.push(data[i]);
  12.     negative.push('-');
  13.   } else {
  14.     positive.push('-');
  15.     negative.push(-data[i]);
  16.   }

  17.   if (i === 0) {
  18.     help.push(0);
  19.   } else {
  20.     sum += data[i - 1];
  21.     if (data[i] < 0) {
  22.       help.push(sum + data[i]);
  23.     } else {
  24.       help.push(sum);
  25.     }
  26.   }
  27.   total = sum;
  28. }


  29. let len = data.length;
  30. let total_array = new Array(len);
  31. total_array.fill(0);
  32. total_array.push(total);

  33. let series_zero = option.series[0];
  34. let series_first = {};
  35. let series_second = {};
  36. let series_total = {};
  37. Object.assign(series_first,series_zero);
  38. Object.assign(series_second,series_zero);
  39. Object.assign(series_total,series_zero);
  40. series_zero.data = help;
  41. series_first.data = positive;
  42. series_second.data = negative;
  43. series_total.data = total_array;
  44. console.log(`total:${total_array}`);
  45. option.xAxis.data.push({
  46. value:"总计"});
  47. series_zero.itemStyle = {
  48.         normal: {
  49.           barBorderColor: 'rgba(0,0,0,0)',
  50.           color: 'rgba(0,0,0,0)'
  51.         },
  52.         emphasis: {
  53.           barBorderColor: 'rgba(1,0,0,0)',
  54.           color: 'rgba(0,0,0,0)'
  55.         }
  56.       };
  57.       
  58. series_first.itemStyle = {
  59.         color: 'green'
  60.       }
  61. series_second.itemStyle = {
  62.         color: 'red'
  63.       }
  64. series_total.itemStyle = {
  65.         color: 'blue'
  66.       }
  67. series_zero.stack = 'all';
  68. series_first.stack = 'all';
  69. series_second.stack = 'all';
  70. series_total.stack = 'all';

  71. series_first.name = '上升';
  72. series_second.name = '下降';
  73. series_total.name = '总计';
  74. option.legend.show = true;
  75. option.legend.data = ["上升","下降","总计"]
  76. option.series = [series_zero,series_first,series_second,series_total];
  77. option.tooltip = {
  78.         show: true
  79. }

  80. return option




复制代码
瀑布图V2.zip (24.39 KB, 下载次数: 6)
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部