Skip to content

Latest commit

Β 

History

History
442 lines (376 loc) Β· 11.4 KB

chart-columnLine.md

File metadata and controls

442 lines (376 loc) Β· 11.4 KB

ColumnLine 차트

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

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

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

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

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

// ν˜Ήμ€

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

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

기본 차트

데이터 νƒ€μž…

λ°μ΄ν„°λŠ” series λ₯Ό 톡해 μž…λ ₯λ°›λŠ”λ‹€. 각 차트의 μ‹œλ¦¬μ¦ˆλŠ” column, line에 각각 μž…λ ₯되며 nameκ³Ό data 쌍으둜 μž…λ ₯ λ°›λŠ”λ‹€. dataλŠ” 값을 λ‚˜νƒ€λ‚΄λŠ” λ°°μ—΄λ‘œ μž…λ ₯ν•œλ‹€.

const data = {
  categories: ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct'],
  series: {
    column: [
      {
        name: 'Seoul',
        data: [11.3, 17.0, 21.0, 24.4, 25.2, 20.4, 13.9],
      },
      {
        name: 'NewYork',
        data: [9.9, 16.0, 21.2, 24.2, 23.2, 19.4, 13.3],
      },
      {
        name: 'Sydney',
        data: [18.3, 15.2, 12.8, 11.8, 13.0, 15.2, 17.6],
      },
      {
        name: 'Moscow',
        data: [4.4, 12.2, 16.3, 18.5, 16.7, 10.9, 4.2],
      },
    ],
    line: [
      {
        name: 'Average',
        data: [11, 15.1, 17.8, 19.7, 19.5, 16.5, 12.3],
      },
    ],
  },
};

image

visible μ˜΅μ…˜

각각의 seriesλŠ” visible μ˜΅μ…˜μ„ κ°€μ§ˆ 수 μžˆλ‹€. visible μ˜΅μ…˜μ€ 처음 μ°¨νŠΈκ°€ κ·Έλ €μ‘Œμ„ λ•Œ μ‹œλ¦¬μ¦ˆλ₯Ό λ‚˜νƒ€λ‚Όμ§€μ— λŒ€ν•œ μ—¬λΆ€λ₯Ό κ²°μ •ν•œλ‹€. 기본값은 true이닀.

const data = {
  categories: ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct'],
  series: {
    column: [
      {
        name: 'Seoul',
        data: [11.3, 17.0, 21.0, 24.4, 25.2, 20.4, 13.9],
        visible: false,
      },
      {
        name: 'NewYork',
        data: [9.9, 16.0, 21.2, 24.2, 23.2, 19.4, 13.3],
      },
      {
        name: 'Sydney',
        data: [18.3, 15.2, 12.8, 11.8, 13.0, 15.2, 17.6],
      },
      {
        name: 'Moscow',
        data: [4.4, 12.2, 16.3, 18.5, 16.7, 10.9, 4.2],
      },
    ],
    line: [
      {
        name: 'Average',
        data: [11, 15.1, 17.8, 19.7, 19.5, 16.5, 12.3],
        visible: false,
      },
    ],
  },
}

μœ„ μ˜΅μ…˜μ„ μ μš©ν•΄ 차트λ₯Ό 생성해보면 μ²΄ν¬λ°•μŠ€κ°€ ν•΄μ œλ˜μ–΄ μƒμ„±λ˜λŠ” 것을 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

image

colorByCategories μ˜΅μ…˜

λ°” 계열 seriesλŠ” colorByCategories μ˜΅μ…˜μ„ κ°€μ§ˆ 수 μžˆλ‹€. colorByCategories μ˜΅μ…˜μ€ 차트의 λ§‰λŒ€ 색을 μΉ΄ν…Œκ³ λ¦¬ λ³„λ‘œ λ‹€λ₯΄κ²Œ 칠할지 κ²°μ •ν•œλ‹€. 기본값은 false이닀.

const data = {
  categories: ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct'],
  series: {
    column: [
      {
        name: 'Seoul',
        data: [11.3, 17.0, 21.0, 24.4, 25.2, 20.4, 13.9],
        colorByCategories: true,
      },
    ],
    line: [
      {
        name: 'Average',
        data: [11, 15.1, 17.8, 19.7, 19.5, 16.5, 12.3],
      },
    ],
  },
}

image

μ˜΅μ…˜

optionsλŠ” 객체둜 μž‘μ„±ν•œλ‹€. 각각 μ°¨νŠΈμ— μ μš©ν•˜κ³  싢은 μ˜΅μ…˜μ€ column, line에 μž‘μ„±ν•œλ‹€. μ‚¬μš©κ°€λŠ₯ν•œ μ˜΅μ…˜μ€ λ‹€μŒκ³Ό κ°™λ‹€.

type options = {
  chart?: {
    //...
  }
  xAxis?: {
    //...
  }
  yAxis?: {
    //...
  }
  legend?: {
    //...
  }
  exportMenu?: {
    //...
  }
  tooltip?: {
    //...
  }
  responsive?: {
    //...
  }
  theme?: {
    // μ•„λž˜ ν…Œλ§ˆ μ±•ν„°μ—μ„œ μ„€λͺ…
  }
  series?: {
    selectable?: boolean;
    column?: {
      selectable?: boolean;
      stack?: boolean | {
        type: 'normal' | 'percent';
        connector?: boolean;
      };
      dataLabels?: {
        visible?: boolean;
        anchor?: 'center' | 'start' | 'end' | 'auto';
        offsetX?: number;
        offsetY?: number;
        formatter?: (value) => string;
        stackTotal?: {
          visible?: boolean;
          formatter?: (value) => string;
        };
      };
    };
    line?: {
      selectable?: boolean;
      spline?: boolena;
      showDot?: boolean;
      dataLabels?: {
        visible?: boolean;
        anchor?: DataLabelAnchor;
        offsetX?: number;
        offsetY?: number;
        formatter?: (value) => string;
      }
    }
    dataLabels?: {
      visible?: boolean;
      anchor?: DataLabelAnchor;
      offsetX?: number;
      offsetY?: number;
      formatter?: (value) => string;
      stackTotal?: {
        visible?: boolean;
        formatter?: (value) => string;
      };
    }
  }
}

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

selectable

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

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

image

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

eventDetectType

νˆ΄νŒμ„ λ‚˜νƒ€λ‚Ό λ•Œ λ°œμƒν•˜λŠ” 마우슀 μ˜€λ²„μ™€ μ‹œλ¦¬μ¦ˆλ₯Ό 선택할 λ•Œ λ°œμƒν•˜λŠ” 마우슀 클릭 μ‹œ 데이터λ₯Ό νƒμ§€ν•˜λŠ” 방법을 μ •μ˜ν•œλ‹€.

νƒ€μž… μ„€λͺ…
grouped Y좕을 κΈ°μ€€μœΌλ‘œ 값이 같은 λͺ¨λ“  데이터가 탐지됨
point κ°œλ³„ μ‹œλ¦¬μ¦ˆ μ˜μ—­μ— λ§ˆμš°μŠ€κ°€ λ‹€κ°€κ°€μ•Ό 탐지. ν˜„μž¬ λ§ˆμš°μŠ€κ°€ 가리킀고 μžˆλŠ” 포인트λ₯Ό κΈ°μ€€μœΌλ‘œ 단 ν•œ 개만 탐지됨
  • κΈ°λ³Έκ°’: 'grouped'

image

eventDetectType: 'point'둜 μ„€μ •ν•  경우 line μ‹œλ¦¬μ¦ˆμ˜ 점과 column μ‹œλ¦¬μ¦ˆμ˜ λ°•μŠ€λ₯Ό 각각 마우슀 포인터 κΈ°μ€€μœΌλ‘œ νƒμ§€ν•œλ‹€.

image

column chart options

컬럼 μ°¨νŠΈμ™€ 라인 μ°¨νŠΈμ—μ„œ μ‚¬μš©ν•  수 μžˆλŠ” μ˜΅μ…˜μ„ 각 series.columnκ³Ό series.line에 μ„€μ •ν•œλ‹€.

const options = {
  series: {
    column: {
      stack: {
        type: 'normal'
      }
    },
    line: {
      showDot: true,
      spline: true
    }
  }

};

image

dataLabels options

series.dataLabels μ˜΅μ…˜μ„ μ§€μ •ν•˜λ©΄ Columnκ³Ό Line μ°¨νŠΈμ—μ„œ λͺ¨λ‘ 데이터 라벨이 ν‘œμ‹œλœλ‹€.

const options = {
  ...
  series: {
    dataLabels: {
      visible: true;
    }
  }
};

image

series μ˜΅μ…˜μ— 각 μ‹œλ¦¬μ¦ˆ λ³„λ‘œ μ˜΅μ…˜μ„ μ •μ˜ν•  수 있으며, 데이터 라벨 κ΄€λ ¨ μ˜΅μ…˜λ„ 각 μ‹œλ¦¬μ¦ˆ λ³„λ‘œ μ’€ 더 μ„Έλ°€ν•˜κ²Œ μ„€μ •ν•΄ 쀄 수 μžˆλ‹€.

type ColumnLineChartSeriesOption = {
  column: { // Column μ‹œλ¦¬μ¦ˆ μ˜΅μ…˜
    ...
    dataLabels: {
      // Column μ‹œλ¦¬μ¦ˆ 데이터 라벨 μ˜΅μ…˜
    }
  },
  line: { // Line μ‹œλ¦¬μ¦ˆ μ˜΅μ…˜
    ...
    dataLabels: {
      // Line μ‹œλ¦¬μ¦ˆ  데이터 라벨 μ˜΅μ…˜
    }
  }
};

μ•„λž˜ μ½”λ“œλŠ” Line μ‹œλ¦¬μ¦ˆμ˜ 데이터 라벨은 ν‘œμ‹œν•΄μ£Όμ§€ μ•Šκ³ , Column μ‹œλ¦¬μ¦ˆμ˜ 데이터 라벨만 ν‘œμ‹œν•˜λ„λ‘ μ„€μ •ν•œ μ˜΅μ…˜μ΄λ‹€.

const options = {
  series: {
    column: {
      stack: true,
      dataLabels: {
        visible: true,
        stackTotal: {
          visible: false
        }
      }
    }
  }
};

image

μ‹œλ¦¬μ¦ˆ theme

각각의 μŠ€νƒ€μΌμ„ 지정할 경우 series.column ν˜Ήμ€ series.line을 μ •μ˜ν•œλ‹€. μ‹œλ¦¬μ¦ˆμ˜ 색상을 μ§€μ •ν•˜κ³  싢은 경우 colorsλ₯Ό μž…λ ₯ν•˜κ±°λ‚˜ 각각 μ‹œλ¦¬μ¦ˆλ₯Ό ꡬ뢄해 색상을 λΆ€μ—¬ν•˜κ³  μ‹Άλ‹€λ©΄ κ΅¬λΆ„ν•΄μ„œ λ„£μ–΄μ£Όλ©΄ λœλ‹€.

interface ColumnLineChartSeriesTheme {
  colors: string[];
  column: {
    // column chart μ‹œλ¦¬μ¦ˆ ν…Œλ§ˆ
  };
  line: {
    // line chart μ‹œλ¦¬μ¦ˆ ν…Œλ§ˆ
  };
};

κ°„λ‹¨ν•œ μ˜ˆμ‹œλ‘œ μ—¬λŸ¬κ°€μ§€ μŠ€νƒ€μΌμ„ 각각의 μ°¨νŠΈμ— 맞게 μž‘μ„±ν•΄λ³΄μž.

const theme = {
  theme: {
    series: {
      colors: ['#70d6ff', '#ff70a6', '#ff9770', '#ffd670', '#bfe000'],
      column: {
        barWidth: 18
      },
      line: {
        dot: {
          radius: 6,
          borderColor: '#ffff00',
          borderWidth: 2
        }
      }
    }
  }
};

κ²°κ³ΌλŠ” λ‹€μŒκ³Ό κ°™λ‹€.

image

각 μ‹œλ¦¬μ¦ˆ λ³„λ‘œ 데이터 라벨의 μŠ€νƒ€μΌμ„ 지정할 경우 series.column.dataLabels λ˜λŠ” series.line.dataLabelsλ₯Ό μ •μ˜ν•œλ‹€.

type ColumnLineChartDataLabelTheme = {
  series: {
    column: {
      dataLabels: {
        // Column μ‹œλ¦¬μ¦ˆ 데이터 라벨 ν…Œλ§ˆ
      }
    },
    line: {
      dataLabels: {
        // Line μ‹œλ¦¬μ¦ˆ 데이터 라벨 ν…Œλ§ˆ
      }
    }
  }
};

κ°„λ‹¨ν•œ μ˜ˆμ‹œλ‘œ Column μ‹œλ¦¬μ¦ˆ 데이터 λΌλ²¨μ—λŠ” κΈ€μž 색상과 크기, κ΅΅κΈ° 등을 μ‘°μ ˆν•˜κ³ , Line μ‹œλ¦¬μ¦ˆ 데이터 λΌλ²¨μ—λŠ” 말풍선 μŠ€νƒ€μΌμ„ λ³€κ²½ν•΄λ³΄μ•˜λ‹€.

const options = {
  series: {
    column: {
      dataLabels: { visible: true, anchor: 'start' }
    },
    line: {
      showDot: true,
      dataLabels: { visible: true, offsetY: -15 }
    }
  },
  theme: {
    series: {
      column: {
        dataLabels: {
          color: '#ffffff',
          fontSize: 10,
          fontWeight: 600
        }
      },
      line: {
        dataLabels: {
          fontSize: 10,
          fontWeight: 300,
          useSeriesColor: true,
          textBubble: {
            visible: true,
            paddingY: 3,
            paddingX: 6,
            arrow: {
              visible: true,
              width: 5,
              height: 5,
              direction: 'bottom'
            }
          }
        }
      }
    }
  }
};

image

column μ°¨νŠΈμ™€ line 차트의 ν…Œλ§ˆλŠ” 각각의 κ°€μ΄λ“œλ₯Ό μ°Έκ³ ν•œλ‹€.