Turned Labels in Vue

Using ApexCharts with Vue

This Turned Labels example wires ApexCharts into Vue through the vue3-apexcharts component.

Install it with npm install vue3-apexcharts apexcharts, then mount the chart with <apexchart type="..." :options="options" :series="series" />.

Vue charts guide
<template>
  <div>
    <div id="chart">
      <apexchart
        type="icicle"
        height="460"
        :options="chartOptions"
        :series="series"
      ></apexchart>
    </div>
  </div>
</template>

<script>
import VueApexCharts from 'vue-apexcharts'

import 'apexcharts/icicle'

export default {
  components: {
    apexchart: VueApexCharts,
  },
  data: function () {
    return {
      series: [
        {
          data: [
            {
              x: 'src',
              children: [
                {
                  x: 'charts',
                  children: [
                    {
                      x: 'bar',
                      children: [
                        { x: 'stacked', y: 42 },
                        { x: 'range', y: 28 },
                        { x: 'radius', y: 16 },
                      ],
                    },
                    {
                      x: 'line',
                      children: [
                        { x: 'area', y: 34 },
                        { x: 'paths', y: 22 },
                      ],
                    },
                    {
                      x: 'pie',
                      children: [
                        { x: 'arcs', y: 26 },
                        { x: 'donut', y: 18 },
                      ],
                    },
                    { x: 'common', y: 30 },
                  ],
                },
                {
                  x: 'modules',
                  children: [
                    {
                      x: 'axes',
                      children: [
                        { x: 'xaxis', y: 30 },
                        { x: 'yaxis', y: 28 },
                        { x: 'grid', y: 20 },
                      ],
                    },
                    {
                      x: 'tooltip',
                      children: [
                        { x: 'labels', y: 24 },
                        { x: 'utils', y: 14 },
                      ],
                    },
                    { x: 'legend', y: 26 },
                    { x: 'anim', y: 34 },
                  ],
                },
                {
                  x: 'utils',
                  children: [
                    { x: 'dates', y: 22 },
                    { x: 'colors', y: 16 },
                    { x: 'dom', y: 14 },
                  ],
                },
                {
                  x: 'svg',
                  children: [
                    { x: 'paths', y: 20 },
                    { x: 'math', y: 12 },
                  ],
                },
                { x: 'assets', y: 24 },
              ],
            },
          ],
        },
      ],
      chartOptions: {
        chart: {
          type: 'icicle',
          height: 460,
        },
        // The library's own palette, lightened: a turned label sits INSIDE its cell
        // on every level, so the fills have to stay light enough to read dark text
        // against, all the way down. The fifth is a steel blue rather than the
        // palette's violet, which goes muddy once it is tinted this far.
        colors: ['#7CC6F0', '#6FD7C1', '#FFC46B', '#F09BA0', '#9AAEC8'],
        title: {
          text: 'Bundle size by source folder',
          align: 'left',
        },
        subtitle: {
          text: 'Every label turned a quarter turn, which suits short names and a deep tree.',
          align: 'left',
        },
        plotOptions: {
          icicle: {
            // Turn EVERY label, rather than only the ones that would be clipped flat.
            // A turned label reads across the band thickness, so this suits short
            // names: with long ones, 'auto' keeps more of them on screen.
            dataLabels: {
              rotate: 'always',
              minSizeToShow: 14,
              style: {
                fontSize: '11px',
                colors: ['#44403C'],
              },
            },
          },
        },
        stroke: {
          width: 1,
          colors: ['#fff'],
        },
      },
    }
  },
}
</script>

<style>
#chart {
  max-width: 900px;
  margin: 35px auto;
}
</style>