Skip to content

Latest commit

Β 

History

History
482 lines (425 loc) Β· 12.3 KB

chart-treemap.md

File metadata and controls

482 lines (425 loc) Β· 12.3 KB

Treemap 차트

μ°¨νŠΈλ³„λ‘œ μ‚¬μš©ν•  수 μžˆλŠ” APIλŠ” 이 κ°€μ΄λ“œμ—μ„œ 닀루지 μ•ŠλŠ”λ‹€. μ‚¬μš© κ°€λŠ₯ν•œ APIκ°€ κΆκΈˆν•˜λ‹€λ©΄ API κ°€μ΄λ“œλ₯Ό μ°Έκ³ ν•˜μž.

차트 μƒμ„±ν•˜κΈ°

Treemap 차트의 생성 방법은 두 가지가 μžˆλ‹€. μƒμ„±μž ν•¨μˆ˜μ™€ 정적 ν•¨μˆ˜λ₯Ό 톡해 생성할 수 μžˆλ‹€. κ²°κ³ΌλŠ” λͺ¨λ‘ 차트의 μΈμŠ€ν„΄μŠ€κ°€ λ°˜ν™˜λœλ‹€. 맀개 λ³€μˆ˜λŠ” μ°¨νŠΈκ°€ κ·Έλ €μ§€λŠ” μ˜μ—­μΈ HTML μš”μ†Œ el, 데이터값인 data, μ˜΅μ…˜κ°’ optionsκ°€ 객체둜 λ“€μ–΄κ°„λ‹€. el 값은 차트의 μ»¨ν…Œμ΄λ„ˆ μ˜μ—­μ΄λ―€λ‘œ 차트 외에 λ‹€λ₯Έ μš”μ†Œλ“€μ΄ ν¬ν•¨λ˜μ–΄ 있으면 μ°¨νŠΈμ— 영ν–₯을 쀄 수 있음으둜 λΉ„μ–΄μžˆλŠ” HTML μš”μ†Œλ₯Ό μ‚¬μš©ν•˜λŠ” 것을 ꢌμž₯ν•œλ‹€.

import { TreemapChart } from '@toast-ui/chart';

const chart = new TreemapChart({el, data, options});

// ν˜Ήμ€

import Chart from '@toast-ui/chart';

const chart = Chart.treemapChart({el, data, options});

기본 차트

데이터 νƒ€μž…

series 값을 μž…λ ₯ λ°›μœΌλ©° label-data ν˜Ήμ€ label-children의 μŒμ„ 이룬닀. clildren은 λ°°μ—΄λ‘œ μž…λ ₯을 λ°›μœΌλ©° 트리의 ν•˜μœ„ 데이터λ₯Ό μž…λ ₯ λ°›λŠ”λ‹€. data 값은 μˆ«μžκ°’μ„ μž…λ ₯λ°›λŠ”λ‹€.

const data = {
  series: [
    {
      label: 'Documents',
      children: [
        {
          label: 'docs',
          children: [
            {
              label: 'pages',
              data: 1.3,
            },
            {
              label: 'keynote',
              data: 2.5,
            },
            {
              label: 'numbers',
              data: 1.2,
            },
          ],
        },
        {
          label: 'photos',
          data: 5.5,
        },
        {
          label: 'videos',
          data: 20.7,
        },
      ],
    },
    {
      label: 'Downloads',
      children: [
        {
          label: 'recent',
          data: 5.3,
        },
        {
          label: '2020',
          data: 10.1,
        },
        {
          label: '2019',
          data: 8.2,
        },
      ],
    },
    {
      label: 'Application',
      data: 16.4,
    },
    {
      label: 'Desktop',
      data: 4.5,
    },
  ],
}

image

Color Value 차트

data값을 κΈ°μ€€μœΌλ‘œ 각 μ‹œλ¦¬μ¦ˆμ˜ 색상을 λ„£λŠ” 것 λŒ€μ‹  색상 값을 λ³„λ„λ‘œ 쀘 값을 κΈ°μ€€μœΌλ‘œ 전체 차트의 μ‹œλ¦¬μ¦ˆ 색상을 정해쀄 수 μžˆλ‹€. useColorValue μ˜΅μ…˜κ°’κ³Ό 데이터에 colorValue값을 μΆ”κ°€ν•΄μ£Όλ©΄ μ μš©λœλ‹€.

μ˜΅μ…˜

  • κΈ°λ³Έκ°’: true
const options = {
  series: {
    useColorValue: true
  }
};

데이터 νƒ€μž…

λ°μ΄ν„°μ˜ κ΅¬μ‘°λŠ” κΈ°λ³Έ μ°¨νŠΈμ™€ λ™μΌν•˜λ©° λŒ€μ‹  colorValue 값을 μΆ”κ°€λ‘œ λ°›λŠ”λ‹€. 값은 숫자 νƒ€μž…μ΄λ‹€.

const options = {
  series: [
    {
      label: 'Asia',
      children: [
        {
          label: 'South Korea',
          data: 99909,
          colorValue: 499.81,
        },
        {
          label: 'Japan',
          data: 364485,
          colorValue: 335.61,
        },
        {
          label: 'Jordan',
          data: 88802,
          colorValue: 86.07,
        },
        {
          label: 'Iraq',
          data: 437367,
          colorValue: 81.6,
        },
      ],
    },
    {
      label: 'Europe',
      children: [
        {
          label: 'UK',
          data: 241930,
          colorValue: 262.84,
        },
        {
          label: 'France',
          data: 640427,
          colorValue: 117.83,
        },
        {
          label: 'Hungary',
          data: 89608,
          colorValue: 106.54,
        },
        {
          label: 'Portugal',
          data: 91470,
          colorValue: 115.35,
        },
      ],
    },
    {
      label: 'America',
      children: [
        {
          label: 'Panama',
          data: 74340,
          colorValue: 52.81,
        },
        {
          label: 'Honduras',
          data: 111890,
          colorValue: 75.15,
        },
        {
          label: 'Uruguay',
          data: 175015,
          colorValue: 19.6,
        },
        {
          label: 'Cuba',
          data: 109820,
          colorValue: 101.47,
        },
      ],
    },
    {
      label: 'Africa',
      children: [
        {
          label: 'Malawi',
          data: 94080,
          colorValue: 146.09,
        },
        {
          label: 'Ghana',
          data: 227533,
          colorValue: 113.13,
        },
        {
          label: 'Togo',
          data: 54385,
          colorValue: 126.28,
        },
        {
          label: 'Benin',
          data: 114305,
          colorValue: 96.61,
        },
      ],
    },
  ],
};

image

μ˜΅μ…˜

optionsλŠ” 객체둜 μž‘μ„±ν•œλ‹€.

type options = {
  chart?: {
    //...
  }
  legend?: {
    //...
  }
  exportMenu?: {
    //...
  }
  tooltip?: {
    //...
  }
  responsive?: {
    //...
  }
  theme?: {
    // μ•„λž˜ ν…Œλ§ˆ μ±•ν„°μ—μ„œ μ„€λͺ…
  }
  series?: {
    useColorValue?: boolean;
    zoomable?: boolean;
    selectable?: boolean;
    dataLabels?: {
      useTreemapLeaf?: boolean;
      visible?: boolean;
      offsetX?: number;
      offsetY?: number;
      formatter?: (value) => string;
    }
  }
}

이 μ°¨νŠΈμ—μ„œ μ‚¬μš©ν•  수 μžˆλŠ” 곡톡 μ˜΅μ…˜μ— λŒ€ν•΄μ„œλŠ” 이 κ°€μ΄λ“œμ—μ„œ 닀루지 μ•ŠλŠ”λ‹€. ν•„μš”ν•˜λ‹€λ©΄ ν•΄λ‹Ή μ˜΅μ…˜μ˜ κ°€μ΄λ“œλ₯Ό μ°Έκ³ ν•˜μž. (링크: chart μ˜΅μ…˜, λ²”λ‘€, 툴팁, 내보내기, responsive μ˜΅μ…˜ )

selectable

image

  • κΈ°λ³Έκ°’: false

ν•΄λ‹Ή μ‹œλ¦¬μ¦ˆλ₯Ό 선택할 수 μžˆλ‹€.

const options = {
  series: {
    selectable: true
  }
};

selectable μ˜΅μ…˜κ³Ό on API의 selectSeries, unselectSeriesλ₯Ό ν•¨κ»˜ μ‚¬μš©ν•  경우 ν•΄λ‹Ή μ‹œλ¦¬μ¦ˆμ— λŒ€ν•œ μ œμ–΄λ₯Ό μΆ”κ°€λ‘œ ν•  수 μžˆλ‹€.

zoomable

zoomable_treemap

  • κΈ°λ³Έκ°’: false

zoomable을 톡해 차트λ₯Ό ν™•λŒ€ ν•  수 μžˆλ‹€.

const options = {
  series: {
    zoomable: true
  }
}

dataLabels

데이터 라벨은 μ°¨νŠΈμ—μ„œ μ‹œλ¦¬μ¦ˆμ— λŒ€ν•œ 값을 ν‘œμ‹œν•œλ‹€. dataLabels μ˜΅μ…˜μ€ λ‹€μŒκ³Ό κ°™λ‹€.

type options = {
  ...
  series?: {
    dataLabels?: {
      visible?: boolean;
      offsetX?: number;
      offsetY?: number;
      formatter?: (value) => string;
      useTreemapLeaf?: boolean;
    }
  }
};
이름 νƒ€μž… μ„€λͺ…
visible boolean 데이터 라벨 ν‘œμ‹œ μ—¬λΆ€
offsetX number 데이터 라벨 μœ„μΉ˜ x μ˜€ν”„μ…‹
offsetY number 데이터 라벨 μœ„μΉ˜ y μ˜€ν”„μ…‹
formatter function 데이터 값을 λ§€κ°œλ³€μˆ˜λ‘œ λ„˜κ²¨λ°›μ•„ 좜λ ₯ ν˜•μ‹ 지정
useTreemapLeaf boolean μžμ‹ 데이터 라벨 ν‘œμ‹œ μ—¬λΆ€

데이터 라벨을 λ…ΈμΆœν•  λ•Œ ν˜„μž¬ 보고 μžˆλŠ” 트리 κ³„μΈ΅μ˜ λ…Έλ“œ λΌλ²¨λ§Œμ„ λ…ΈμΆœν•œλ‹€.

// κΈ°λ³Έ
const options = {
  series: {
    dataLabels: { visible: true }
  }
};

image

ν•˜μœ„ λ…Έλ“œλ“€μ˜ 라벨을 λ…ΈμΆœν•˜κ³  싢을 경우 useTreemapLeaf μ˜΅μ…˜μ„ 켜주면 λœλ‹€.

// μžμ‹ 데이터 라벨 ν‘œμ‹œ
const options = {
  series: {
    dataLabels: {
      visible: true,
      useTreemapLeaf: true
    }
  }
};

μ‹œλ¦¬μ¦ˆ theme

Treemap μ°¨νŠΈμ—μ„œ μˆ˜μ •ν•  수 μžˆλŠ” μ‹œλ¦¬μ¦ˆ ν…Œλ§ˆμ΄λ‹€. 데이터 라벨 ν…Œλ§ˆλŠ” ν™”μ‚΄ν‘œκ°€ μ—†λŠ” 말풍선 μŠ€νƒ€μΌμ„ μ‚¬μš©ν•  수 μžˆλ‹€.

interface TreemapChartSeriesTheme {
  colors?: string[];
  startColor?: string;
  endColor?: string;
  borderColor?: string;
  borderWidth?: number;
  select?: {
    color?: string;
    borderColor?: string;
    borderWidth?: number;
  };
  hover?: {
    color?: string;
    borderColor?: string;
    borderWidth?: number;
  };
  dataLabels?: {
    useSeriesColor?: boolean;
    lineWidth?: number;
    textStrokeColor?: string;
    shadowColor?: string;
    shadowBlur?: number;
    fontSize?: number;
    fontFamily?: string;
    fontWeight?: string | number;
    color?: string;
    textBubble?: {
      visible?: boolean;
      paddingX?: number;
      paddingY?: number;
      backgroundColor?: string;
      borderRadius?: number;
      borderColor?: string;
      borderWidth?: number;
      shadowColor?: string;
      shadowOffsetX?: number;
      shadowOffsetY?: number;
      shadowBlur?: number;
    };
  };
}
이름 νƒ€μž… μ„€λͺ…
colors string[] μ‹œλ¦¬μ¦ˆμ˜ 색상
startColor string useColorValue: true일 λ•Œ colorValue κ°’μ˜ 색상 기쀀이 λ˜λŠ” μ‹œμž‘κ°’
endColor string useColorValue: true일 λ•Œ colorValue κ°’μ˜ 색상 기쀀이 λ˜λŠ” 끝값
borderColor string μ‹œλ¦¬μ¦ˆμ˜ ν…Œλ‘λ¦¬ 색상
borderWidth number μ‹œλ¦¬μ¦ˆμ˜ ν…Œλ‘λ¦¬ λ„ˆλΉ„
select object selectable: true이며 μ‹œλ¦¬μ¦ˆκ°€ 선택 λ˜μ—ˆμ„ λ•Œ μ μš©λ˜λŠ” μŠ€νƒ€μΌ
hover object 데이터에 마우슀λ₯Ό μ˜¬λ Έμ„ λ•Œ μŠ€νƒ€μΌ
dataLabels object 데이터 라벨 μŠ€νƒ€μΌ
dataLabels.useSeriesColor boolean κΈ€μž 색상을 μ‹œλ¦¬μ¦ˆ μƒ‰μƒμœΌλ‘œ μ‚¬μš©ν• μ§€ μ—¬λΆ€
dataLabels.lineWidth number ν…μŠ€νŠΈ μ„  λ‘κ»˜
dataLabels.textStrokeColor string ν…μŠ€νŠΈ μ„  색상
dataLabels.shadowColor string ν…μŠ€νŠΈ 그림자 색상
dataLabels.shadowBlur number ν…μŠ€νŠΈ 그림자 Blur
dataLabels.fontSize number κΈ€μž 크기
dataLabels.fontFamily string 폰트λͺ…
dataLabels.fontWeight string κΈ€μž κ΅΅κΈ°
dataLabels.color string κΈ€μž 색상, useSeriesColor: true둜 μ„€μ •ν•œκ²½μš° 이 μ˜΅μ…˜μ€ λ™μž‘λ˜μ§€ μ•ŠμŒ
dataLabels.textBubble object 말풍선 λ””μžμΈ μ„€μ •
dataLabels.textBubble.visible boolean 말풍선 λ””μžμΈ μ‚¬μš© μ—¬λΆ€
dataLabels.textBubble.paddingX number μˆ˜ν‰ μ—¬λ°±
dataLabels.textBubble.paddingY number 수직 μ—¬λ°±
dataLabels.textBubble.backgroundColor string 말풍선 배경색
dataLabels.textBubble.borderRadius number 말풍선 ν…Œλ‘λ¦¬μ˜ λ‘₯κ·Ό λͺ¨μ„œλ¦¬ κ°’
dataLabels.textBubble.borderColor string 말풍선 ν…Œλ‘λ¦¬ 색상
dataLabels.textBubble.borderWidth number 말풍선 ν…Œλ‘λ¦¬ λ‘κ»˜
dataLabels.textBubble.shadowColor string 말풍선 그림자 색상
dataLabels.textBubble.shadowOffsetX number 말풍선 그림자 Offset X
dataLabels.textBubble.shadowOffsetY number 말풍선 그림자 Offset Y
dataLabels.textBubble.shadowBlur number 말풍선 그림자 Blur

startColor와 endColor

series.useColorValueμ˜΅μ…˜ 값이 true일 λ•Œ 기쀀이 λ˜λŠ” 색상 값이닀. startColor와 endColor 색상 값을 κΈ°μ€€μœΌλ‘œ μž…λ ₯받은 colorValue의 색상을 κ²°μ •ν•œλ‹€.

κ°„λ‹¨ν•œ μ˜ˆμ‹œλ‘œ startColorλ₯Ό #4A76B2,

image

endColorλ₯Ό #221271둜 μ§€μ •ν•˜λ©΄ colorValueκ°€ 높을 수둝 endColor에 κ°€κΉŒμš΄ 색깔을 κ°€μ§ˆ 것이닀.

image

const options = {
  series: {
    theme: {
      startColor: '#4A76B2',
      endColor: '#221271'
    }
  }
}

image

μ•„λž˜ μ½”λ“œλŠ” 데이터 라벨의 ν…Œλ§ˆλ₯Ό μ μš©ν•˜μ—¬ κΈ€μž μŠ€νƒ€μΌμ„ λ³€κ²½ν•œ μ˜΅μ…˜μ΄λ‹€.

const options = {
  series: {
    dataLabels: { visible: true }
  },
  theme: {
    series: {
      dataLabels: {
        fontFamily: 'monaco',
        fontSize: 16,
        fontWeight: '800',
        useSeriesColor: true,
        lineWidth: 3,
        textStrokeColor: '#ffffff',
        shadowColor: '#ffffff',
        shadowBlur: 10
      }
    }
  }
};

image