Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

306
Vistas
Treemap Echarts Dynamic label text

Can you make the text size dynamically dependant on the size of a box on a treemap label?

all I can find in the docs is how to hardcode it

https://echarts.apache.org/en/option.html#series-treemap.label.fontFamily

 label: {
      fontSize: 16
    }

The idea being that the smaller the box the smaller the font.

map

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

There are a couple of ways to achieve this. Probably the best way would be to add a labelLayout function to the series. There is an example in the eCharts GitHub repo here. So the series in the provided example would end up looking like this:

      series: [
        {
          name: 'Disk Usage',
          type: 'treemap',
          visibleMin: 300,
          label: {
            show: true,
            formatter: '{b}'
          },
          labelLayout: function (params) {
            if (params.rect.width < 5 || params.rect.height < 5) {
                return {  fontSize: 0  };
            }
            return {
                fontSize: Math.min(Math.sqrt(params.rect.width * params.rect.height) / 10, 20)
            };
          },
          itemStyle: {
            borderColor: '#fff'
          },
          levels: getLevelOption(),
          data: diskData
        }
      ]

alternatively, you could alter the label and add a formatter to be a function and which pipes through rich formatting. In the example, send in the Parameters object and we grab the root element value (total overall Disk Usage from the provided example), then find a ratio of the current value to the total value.

          label: {
            show: true,
            formatter: function (params) {
                let totSize=  params.treePathInfo[0].value;
                let size=(params.value/totSize)*100;
                if (size>8) {
                   return `{l|${params.name}}`
                }
                if (size>2) {
                   return `{m|${params.name}}`
                }
                return `{s|${params.name}}`
            },
            rich: {
              l: {
                fontSize: 20,
              },
              m: {
                fontSize: 15,
              },
              s: {
                fontSize: 10,
              }
            },
          },
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda