找回密码
 立即注册

QQ登录

只需一步,快速开始

@Martin.Zhang
超级版主   /  发表于:2024-2-4 15:31  /   查看:579  /  回复:0
显示效果:
image.png874830016.png
实现步骤:
1.使用Echarts图表
image.png499259643.png
2.绑定数据
image.png814042663.png
3.属性中调整自定义属性
image.png470920409.png
代码内容:
  1. const x1=option.xAxis.data.map(x=>{
  2.         return x.value;
  3.     })
  4.     const data=option.series[0].data.map(x=>{
  5.         return x.value;
  6.     })
  7.     const payload = {
  8.         data: {
  9.             unit: [''],
  10.             x: x1,
  11.             data1: data,
  12.         },
  13.     };

  14.     const unit = payload.data.unit || [];
  15.     const x = payload.data.x || [];
  16.     const data1 = payload.data.data1 || [];
  17.     const title = payload.data.title || [];
  18.     const max = Math.max(...data1)

  19.     const maxData = data1.map((item, index) => {
  20.         return {
  21.             value: [max, index],
  22.             name: x[index],
  23.         };
  24.     });

  25.     const barData = data1.map((item, index) => {
  26.         return {
  27.             value: [item, index],
  28.             name: x[index],
  29.         };
  30.     });

  31.     const _option = {
  32.         grid:{
  33.             top:option.grid.top,
  34.             left: option.grid.left,
  35.             right: option.grid.right,
  36.             bottom:option.grid.bottom-30,
  37.             containLabel: true,
  38.         },
  39.         legend: option.legend,
  40.         tooltip:  option.tooltip,
  41.         xAxis: {
  42.             show: false,
  43.         },
  44.         yAxis: [
  45.             {
  46.                 name: '',
  47.                 type: 'category',
  48.                 inverse: true,
  49.                 axisLabel: {
  50.                     show: false,
  51.                 },
  52.                 splitLine: {
  53.                     show: false,
  54.                 },
  55.                 axisTick: {
  56.                     show: false,
  57.                 },
  58.                 axisLine: {
  59.                     show: false,
  60.                 },
  61.                 data: x,
  62.             },
  63.             {
  64.                 type: 'category',
  65.                 inverse: true,
  66.                 axisTick: 'none',
  67.                 axisLine: 'none',
  68.                 show: true,
  69.                 axisLabel: option.yAxis.axisLabel,
  70.                 data: data1,
  71.             },
  72.         ],
  73.         series: [
  74.             {
  75.                 name: '值',
  76.                 type: 'bar',
  77.                 zlevel: 1,
  78.                 itemStyle: {
  79.                     barBorderRadius: 0,
  80.                     color: '#26a69a',
  81.                 },
  82.                 barWidth: 20,
  83.                 data: barData,
  84.                 label: {                 
  85.                     ...option.xAxis.axisLabel,
  86.                     position: [0, -16],
  87.                     align: 'left',
  88.                     show: true,
  89.                     formatter: (params) => {
  90.                         return params.name;
  91.                     },
  92.                 },
  93.                 barMaxWidth: 40,
  94.                 markLine: {
  95.                     label: {
  96.                         color: '#26a69a',
  97.                     },
  98.                 },
  99.             },
  100.             {
  101.                 name: '背景',
  102.                 type: 'bar',
  103.                 barWidth: 20,
  104.                 barGap: '-100%',
  105.                 data: maxData,
  106.                 itemStyle: {
  107.                     normal: {
  108.                         color: 'rgba(105,131,242,.3)',
  109.                         barBorderRadius: 30,
  110.                     },
  111.                     borderRadius: [5, 5, 0, 0],
  112.                 },
  113.                 label: {
  114.                     show: false,
  115.                 },
  116.                 barMaxWidth: 40,
  117.                 markLine: {
  118.                     label: {
  119.                         color: '#26a69a',
  120.                     },
  121.                 },
  122.             },
  123.             {
  124.                 name: '内圆',
  125.                 type: 'scatter',
  126.                 hoverAnimation: false,
  127.                 data: barData,
  128.                 yAxisIndex: 0,
  129.                 symbolSize: 22,
  130.                 itemStyle: {
  131.                     normal: {
  132.                         color: '#26a69a',
  133.                         opacity: 1,
  134.                     },
  135.                 },
  136.                 zlevel: 2,
  137.                 label: {
  138.                     show: false,
  139.                 },
  140.             },
  141.             {
  142.                 name: '外圆',
  143.                 type: 'scatter',
  144.                 hoverAnimation: false,
  145.                 data: barData,
  146.                 yAxisIndex: 0,
  147.                 symbolSize: 28,
  148.                 symbol:
  149.                     'path://M512 960C264.576 960 64 759.424 64 512S264.576 64 512 64s448 200.576 448 448-200.576 448-448 448z m0-268.8a179.2 179.2 0 1 0 0-358.4 179.2 179.2 0 0 0 0 358.4z',
  150.                 itemStyle: {
  151.                     color: 'rgb(255, 255, 255)',
  152.                     opacity: 1,
  153.                     borderColor: 'rgba(44, 111, 226, 0.2)',
  154.                     borderWidth: 2,
  155.                 },
  156.                 zlevel: 3,
  157.                 label: {
  158.                     show: false,
  159.                 },
  160.             },
  161.         ],
  162.     };
  163. return _option;
复制代码

运行,浏览效果。
示例案例: wyn-export-20240204153116.zip (398.79 KB, 下载次数: 16)

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部