echart自定义统计图分享

70
0

chestnut 数据领袖Lv6

发表于2025-1-8 19:58

楼主
本帖最后由 chestnut 于 2025-1-8 20:00 编辑

Echart自定义统计图,计算样式如图:



Echart组件-自定义,脚本如下:
  1. let map = {
  2. 采购量: [12,34,56,78,90,13,24,56,78,90,123,111],
  3.   销售量: [11,22,33,44,55,65,43,21,10,11,22,33],
  4.   销售单价: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 10.3, 13.4, 13.0, 16.5, 12.0, 0, 87.5],
  5.   市场价: [1.0, 2.2, 4.3, 4.5, 7.3, 10.2, 11.3, 15.4, 18.0, 18.5, 12.0, 0, 104.1]
  6. };

  7. option = {
  8.   title: {
  9.     text: '2024年1-12月xxx量价对比图'
  10.   },
  11.   darkMode: true,
  12.   grid: {
  13.     x: 150,
  14.     // y:45,
  15.     x2: 50,
  16.     y2: 210
  17.     // borderWidth:1
  18.   },
  19.   tooltip: {
  20.     trigger: 'axis',
  21.     axisPointer: {
  22.       type: 'cross',
  23.       crossStyle: {
  24.         color: '#999'
  25.       }
  26.     }
  27.   },
  28.   toolbox: {
  29.     feature: {
  30.       dataView: { show: true, readOnly: false },
  31.       magicType: { show: true, type: ['line', 'bar'] },
  32.       restore: { show: true },
  33.       saveAsImage: { show: true }
  34.     }
  35.   },
  36.   legend: {
  37.     align: 'right',
  38.     itemGap: 30,
  39.     orient: 'vertical',
  40.     textStyle: { color: '#000' },
  41.     bottom: 10,
  42.     left: 0,
  43.     data: ['采购量', '销售量', '销售单价', '平均单价']
  44.   },
  45.   xAxis: [
  46.     {
  47.       type: 'category',
  48.       max: 12,
  49.       interval: Math.ceil(12) / 12,
  50.       // axisTick: {
  51.       //   interval: 12/12
  52.       // },
  53.       axisLabel: {
  54.         fontWeight: 'bold',
  55.         show: true,
  56.         textStyle: {
  57.           // color: "#f4f4f4",
  58.           fontSize: '14px'
  59.         }
  60.       },
  61.       data: [
  62.         '1月',
  63.         '2月',
  64.         '3月',
  65.         '4月',
  66.         '5月',
  67.         '6月',
  68.         '7月',
  69.         '8月',
  70.         '9月',
  71.         '10月',
  72.         '11月',
  73.         '12月',
  74.         '1-12月\n累计'
  75.       ],
  76.       axisPointer: {
  77.         type: 'shadow'
  78.       }
  79.     },
  80.     {
  81.       position: 'bottom', // 将分组x轴位置定至底部,不然默认在顶部
  82.       offset: 45, // 向下偏移,使分组文字显示位置不与原x轴重叠
  83.       // axisLine: {
  84.       //   show: false // 隐藏分组x轴的轴线
  85.       // },
  86.       axisTick: {
  87.         length: -200, // 延长刻度线做分组线
  88.         inside: true, // 使刻度线相对轴线在上面与原x轴相接,默认在轴线下方
  89.         lineStyle: { color: '#000' } // 非必须,仅为了演示,明显标示出分组刻度线
  90.         // interval: function(index, value) {
  91.         //   return index === 0 || index === 2 || index === 5; // 在0、5、6处各画一条刻度线
  92.         // }
  93.         // interval: 1,
  94.       },
  95.       // min: -30,
  96.       max: 12,
  97.       interval: 1,
  98.       axisLabel: {
  99.         inside: true, // 使刻度名称相对轴线在上面与原x轴相接,默认在轴线下方
  100.         interval: 0 // 强制显示全部刻度名
  101.       },
  102.       data: ['']
  103.     },
  104.     {
  105.       position: 'bottom', // 将分组x轴位置定至底部,不然默认在顶部
  106.       offset: 36, // 向下偏移,使分组文字显示位置不与原x轴重叠
  107.       max: 12,
  108.       interval: Math.ceil(12) / 12,
  109.       axisTick: {
  110.         length: 0, // 延长刻度线做分组线
  111.         inside: true, // 使刻度线相对轴线在上面与原x轴相接,默认在轴线下方
  112.         lineStyle: { color: '#000' } // 非必须,仅为了演示,明显标示出分组刻度线
  113.       },
  114.       axisLabel: {
  115.         inside: true, // 使刻度名称相对轴线在上面与原x轴相接,默认在轴线下方
  116.         interval: 0 // 强制显示全部刻度名
  117.       }
  118.     },
  119.     {
  120.       position: 'bottom', // 将分组x轴位置定至底部,不然默认在顶部
  121.       offset: 75, // 向下偏移,使分组文字显示位置不与原x轴重叠
  122.       max: 12,
  123.       interval: 1,
  124.       axisTick: {
  125.         length: 0, // 延长刻度线做分组线
  126.         inside: true, // 使刻度线相对轴线在上面与原x轴相接,默认在轴线下方
  127.         lineStyle: { color: '#000' } // 非必须,仅为了演示,明显标示出分组刻度线
  128.       },
  129.       axisLabel: {
  130.         inside: true, // 使刻度名称相对轴线在上面与原x轴相接,默认在轴线下方
  131.         interval: 0 // 强制显示全部刻度名
  132.       },
  133.       data: [12,34,56,78,90,13,24,56,78,90,123,111]
  134.     },
  135.     {
  136.       position: 'bottom', // 将分组x轴位置定至底部,不然默认在顶部
  137.       offset: 120, // 向下偏移,使分组文字显示位置不与原x轴重叠
  138.       max: 12,
  139.       interval: Math.ceil(12) / 12,
  140.       axisTick: {
  141.         length: 0, // 延长刻度线做分组线
  142.         inside: true, // 使刻度线相对轴线在上面与原x轴相接,默认在轴线下方
  143.         lineStyle: { color: '#000' } // 非必须,仅为了演示,明显标示出分组刻度线
  144.       },
  145.       axisLabel: {
  146.         inside: true, // 使刻度名称相对轴线在上面与原x轴相接,默认在轴线下方
  147.         interval: 0 // 强制显示全部刻度名
  148.       },
  149.       data: [11,22,33,44,55,65,43,21,10,11,22,33]
  150.     },
  151.     {
  152.       position: 'bottom', // 将分组x轴位置定至底部,不然默认在顶部
  153.       offset: 160, // 向下偏移,使分组文字显示位置不与原x轴重叠
  154.       max: 12,
  155.       interval: 1,
  156.       axisTick: {
  157.         length: 0, // 延长刻度线做分组线
  158.         inside: true, // 使刻度线相对轴线在上面与原x轴相接,默认在轴线下方
  159.         lineStyle: { color: '#000' } // 非必须,仅为了演示,明显标示出分组刻度线
  160.       },
  161.       axisLabel: {
  162.         inside: true, // 使刻度名称相对轴线在上面与原x轴相接,默认在轴线下方
  163.         interval: 0 // 强制显示全部刻度名
  164.       },
  165.       data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 10.3, 13.4, 13.0, 16.5, 12.0, 0, 87.5]
  166.     },
  167.     {
  168.       position: 'bottom', // 将分组x轴位置定至底部,不然默认在顶部
  169.       offset: 200, // 向下偏移,使分组文字显示位置不与原x轴重叠
  170.       max: 12,
  171.       interval: 1,
  172.       axisTick: {
  173.         length: 0, // 延长刻度线做分组线
  174.         inside: true, // 使刻度线相对轴线在上面与原x轴相接,默认在轴线下方
  175.         lineStyle: { color: '#000' } // 非必须,仅为了演示,明显标示出分组刻度线
  176.       },
  177.       axisLabel: {
  178.         inside: true, // 使刻度名称相对轴线在上面与原x轴相接,默认在轴线下方
  179.         interval: 0 // 强制显示全部刻度名
  180.       },
  181.       data: [1.0, 2.2, 4.3, 4.5, 7.3, 10.2, 11.3, 15.4, 18.0, 18.5, 12.0, 0, 104.1]
  182.     }
  183.   ],
  184.   yAxis: [
  185.     {
  186.       type: 'value',
  187.       name: '数量:吨',
  188.       // min: 0,
  189.       max: Math.ceil(115),
  190.       interval: Math.ceil(115) / 5,
  191.       axisLabel: {
  192.         formatter: '{value}',
  193.         textStyle: {
  194.           // color: "#f4f4f4",
  195.           fontSize: '14px'
  196.         }
  197.       }
  198.     },
  199.     {
  200.       type: 'value',
  201.       name: '价格:元/吨',
  202.       // min: 0,
  203.       max: Math.ceil(22500),
  204.       // splitNumber: 6,
  205.       interval: Math.ceil(22500) / 5,
  206.       axisLabel: {
  207.         formatter: '{value}'
  208.       }
  209.     }
  210.   ],
  211.   series: [
  212.     {
  213.       name: '采购量',
  214.       type: 'bar',
  215.       unit: '吨',
  216.       groupName: '采购/销售量',
  217.       data: map['采购量'],
  218.       itemStyle: {
  219.         color: 'rgb(242, 143, 133)'
  220.       }
  221.     },
  222.     {
  223.       name: '销售量',
  224.       type: 'bar',
  225.       unit: '吨',
  226.       groupName: '采购/销售量',
  227.       data: map['销售量'],
  228.       itemStyle: {
  229.         color: 'rgb(183, 222, 232)'
  230.       }
  231.     },
  232.     {
  233.       name: '销售单价',
  234.       type: 'line',
  235.       yAxisIndex: 1,
  236.       unit: '元/吨',
  237.       data: map['销售单价'],
  238.       itemStyle: {
  239.         color: 'rgb(196, 23, 23)'
  240.       },
  241.       lineStyle: {
  242.         width: 5
  243.       }
  244.     },
  245.     {
  246.       name: '平均单价',
  247.       type: 'line',
  248.       yAxisIndex: 1,
  249.       unit: '元/吨',
  250.       data: map['市场价'],
  251.       itemStyle: {
  252.         color: 'rgb(0, 112, 192)'
  253.       },
  254.       lineStyle: {
  255.         width: 5,
  256.         type: [10, 10],
  257.         dashOffset: 5
  258.       }
  259.     }
  260.   ]
  261. };
  262. return option;
复制代码


示例为固定值,改为取表格数据,用宏取表元,如:
  1. let map = {
  2.             数据1: <#=GRID1.B2$#>,数据2: <#=GRID1.C2$#>,
  3.           };
复制代码





最近看过此主题的会员

esen_4YNPQEX87K

0个回答

只看楼主

登录后可回答问题,请登录注册

快速回复 返回顶部 返回列表

小时

全天响应

分钟

快速处理问题

工程师强势助力

明星产品
解决方案
联系合作

400咨询:400-0011-866

技术支持QQ:400-0011-866(工作日9:00-18:00)

产品建议邮箱yixin@esensoft.com

关注我们

扫TA学习更多干货

一对一专家交流

版权所有© 2006-2024 北京亿信华辰软件有限责任公司 京ICP备07017321号 京公网安备11010802016281号