echarts漏斗图自定义label左右位置设置

import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
import { Input, message, Button, Select, DatePicker, Row, Col } from 'antd';
import * as echarts from 'echarts';
import Icon from '@/components/Icon';
import style from '../../index.less';
const colors = ['#30E3E5', '#5AA4FC', '#BE3EF2 ', '#F0C219', '#1B4BFE'];
export default (props) => {
  useEffect(() => {
    charts(...props.data);
  }, [props.data]);
  const charts = (sourceData) => {
    const { data, text } = sourceData;
    if (!document.getElementById(props.id ? props.id : 'funnel')) {
      return;
    }
    // 基于准备好的dom,初始化echarts实例
    var myChart = echarts.init(document.getElementById(props.id ? props.id : 'funnel'));
    // 绘制图表
    myChart.setOption({
      // 整个图例
      grid: {
        left: '3%',
        right: '3%',
        bottom: '7%',
        containLabel: true,
      },
      legend: { left: 10 },
      title: {
        text: text, //主标题文本,'\n'指定换行
        x: 'center', //水平安放位置,默认为'left',可选为:'center' | 'left' | 'right' | {number}(x坐标,单位px)
        y: '10', //垂直安放位置,默认为top,可选为:'top' | 'bottom' | 'center' | {number}(y坐标,单位px)
        textStyle: {
          //主标题文本样式{"fontSize": 18,"fontWeight": "bolder","color": "#333"}
          // fontFamily: 'Arial, Verdana, sans...',
          fontSize: 16,
          fontStyle: 'normal',
          fontWeight: 'bold',
        },
      },
      tooltip: {
        show: false,
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c}',
      },
      legend: {
        // data: ['Show', 'Click', 'Visit', 'Inquiry', 'Order'],
        show: false,
      },
      series: [
        {
          name: 'Funnel',
          type: 'funnel',
          left: '5%',
          right: '5%',
          top: '15%',
          // x2: 80,
          bottom: '10%',
          width: '80%',
          // height: {totalHeight} - y - y2,
          min: 0,
          max: 100,
          minSize: '0%',
          maxSize: '100%',
          sort: 'descending',
          // sort: 'ascending',
          gap: 0,
          funnelAlign: 'center',
          /*   markLine: {
            symbol: 'none',
            zlevel: 0,
            data: [
              [
                { x: '45%', y: '28%' },
                {
                  x: '90%',
                  y: '28%',
                  value: 20,
                  lineStyle: { color: 'rgba(255, 255, 255, 0)' },
                },
              ],
              [
                { x: '45%', y: '54%' },
                {
                  x: '90%',
                  y: '54%',
                  value: 40,
                  lineStyle: { color: 'rgba(255, 255, 255, 0)' },
                },
              ],
              [
                { x: '45%', y: '80%' },
                {
                  x: '90%',
                  y: '80%',
                  value: 60,

                  lineStyle: { color: 'rgba(255, 255, 255, 0)' },
                },
              ],
            ],
          }, */

          label: {
            show: true,
            position: 'center',
            color: '#000',
            textBorderColor: '#000',
            formatter: function (params) {
              return `{title|${params.name}}{value|${params.value}} `;
            },
            textStyle: {
              rich: {
                title: {
                  width: 100,
                  textAlign: 'left',
                  fontSize: 16,
                  padding: [0, 320, 0, 0],
                },
                value: {
                  width: 100,
                  textAlign: 'right',
                  fontSize: 14,
                  padding: [0, 0, 0, 320],
                },
              },
            },
          },
          labelLine: {
            show: false,
            length: 20,
            lineStyle: {
              width: 1,
              type: 'solid',
            },
          },

          emphasis: {
            label: {
              fontSize: 20,
            },
          },
          data: data,
        },
      ],
    });
  };
  return (
    <div>
      <div
        style={{ width: props.width, height: props.height }}
        id={props.id ? props.id : 'funnel'}
      />
    </div>
  );
};

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值