๐Ÿ‘ฉ‍๐Ÿ’ป/Vue

[Vue-todo-list] #3 chart.js๋กœ todo data ์‹œ๊ฐํ™”ํ•˜๊ธฐ (1) - Line Chart

ํ•œ๋‚˜ 2021. 2. 8. 02:34

2021/02/08 - [๐Ÿ‘ฉ‍๐Ÿ’ป/Vue.js] - [Vue-todo-list] #2 ์นดํ…Œ๊ณ ๋ฆฌ๊ฐ€ ์žˆ๋Š” Todo List ๋งŒ๋“ค๊ธฐ

2021/02/08 - [๐Ÿ‘ฉ‍๐Ÿ’ป/Vue.js] - [Vue-todo-list] #1 Date ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•ด ๋‹ฌ๋ ฅ ์ˆซ์ž ๊ตฌํ•˜๊ธฐ/์ง€๋‚œ ๋‚ ์งœ, ์˜ค๋Š˜ ๋‚ ์งœ ๊ตฌ๋ณ„์„ ์œ„ํ•œ CSS ์Šคํƒ€์ผ๋ง


 

todolist ์˜ˆ์ œ์˜ ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„๋Š” chart.js ์—ฐ์Šต์„ ์œ„ํ•ด์„œ Pie chart์™€ line chart ๋‘ ๊ฐœ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” Daily Report๋กœ ๊พธ๋ช„๋‹ค. Line chart์˜ ๊ฒฝ์šฐ localStorage์— ์ €์žฅ๋˜๋Š” todo ๊ฐ์ฒด์˜ createdAt Date ๊ฐ์ฒด์™€ ์™„๋ฃŒ๊ฐ€ ๋  ๋•Œ ์ƒ์„ฑ๋˜๋Š” completedAt Date ๊ฐ์ฒด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์•Œ๋งž์€ ๋‚ ์งœ์— ํ•ด๋‹นํ•˜๋Š” todo ๊ฐ์ฒด์˜ length์— ๋”ฐ๋ผ ๋‘ ๊ฐœ์˜ Line์„ ๋น„๊ตํ•ด์ฃผ๋Š” ์ฐจํŠธ๋กœ ๋งŒ๋“ค์—ˆ๋‹ค.

 

ํŒŒ๋ž€์ƒ‰ ๋ผ์ธ์€ ํ•ด๋‹น ๋‚ ์งœ์— ์ƒ์„ฑ๋œ todo์˜ ๊ฐฏ์ˆ˜, ๋นจ๊ฐ„์ƒ‰ ๋ผ์ธ์€ ์™„๋ฃŒํ•œ todo์˜ ๊ฐœ์ˆ˜์ธ๋ฐ, ์˜ค๋Š˜ ๋‚ ์งœ๊ฐ€ ๋ผ๋ฒจ์—์„œ ๊ฐ€์žฅ ์˜ค๋ฅธ์ชฝ์— ์œ„์น˜ํ•˜๋„๋ก ํ•ด์„œ ์ตœ๊ทผ 7์ผ ๊ฐ„์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋„๋ก ํ–ˆ๋‹ค.

 

๋‹ค๋งŒ ํ˜„์žฌ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ todo done ๋ชฉ๋ก์— ์žˆ๋Š” todo๋ฅผ ์‚ญ์ œํ•  ๊ฒฝ์šฐ ๋ฐ์ดํ„ฐ๊ฐ€ ์—ฐ๋™๋˜์–ด ์žˆ๋Š” Calendar์™€ Chart ๋ชจ๋‘์—์„œ๋„ ์‹œ๊ฐํ™”๋  ์ž๋ฃŒ๊ฐ€ ์—†์–ด ๋‚˜ํƒ€๋‚˜์ง€ ์•Š๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ๊ธด ํ•˜๋‹ค.

 

npm์œผ๋กœ vue-chart.js๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€ ํ›„, LineChart.js์— import ํ•ด์ฃผ์—ˆ๋‹ค.

// LineChart.js
import { Vue } from "vue-property-decorator";
import { Line } from "vue-chartjs";

 

์ตœ๊ทผ์˜ 7์ผ ๊ฐ„์˜ todo๋ฅผ filterํ•œ latestTodos ๋ฐฐ์—ด, ๋น„๊ต๊ตฐ์ด ๋  ์ตœ๊ทผ 7์ผ ๊ฐ„์˜ ์™„๋ฃŒ๋œ todos, ๊ทธ๋ฆฌ๊ณ  todos์˜ ๊ฐฏ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ด์„œ ๊ณ„์‚ฐ ์‹œ์— ์‚ฌ์šฉํ•˜๊ฒŒ ๋  temporary array์ธ numDaysLabels๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์žก์•„์ฃผ์—ˆ๋‹ค.

chartdata๋Š” chart.js guide document์—์„œ ์ •์˜ํ•œ ๋Œ€๋กœ ํ˜•์‹์„ ์ง€์ผœ ์ž‘์„ฑํ•ด์ค€๋‹ค.

 

๋‚˜๋Š” ๋‘ ๊ฐœ์˜ ๋ผ์ธ์„ ๊ฐ–๋Š” ์ฐจํŠธ๋ฅผ ๊ทธ๋ฆด ์˜ˆ์ •์ด์—ˆ์œผ๋‹ˆ datasets์— ๋‘ ๊ฐ์ฒด๋ฅผ ๋งˆ๋ จํ–ˆ๊ณ , sub label์—๋Š” ๊ฐ๊ฐ ์ด๋ฆ„์„ ๋ถ™์—ฌ์ฃผ์—ˆ์ง€๋งŒ, ์ƒ‰์ธ ์—ญํ• ์„ ํ•˜๋Š” chartdata์˜ labels๋Š” ๋น„์›Œ๋‘๊ณ  ๋™์ ์œผ๋กœ ์ƒ์„ฑํ•ด์ฃผ๊ธฐ๋กœ ํ–ˆ๋‹ค.

 

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ datasets์˜ ๊ฐ ๊ฐ์ฒด์˜ data ์†์„ฑ๋„ ๋นˆ ๋ฐฐ์—ด๋กœ ์ดˆ๊ธฐํ™”๋งŒ ํ•ด๋‘์—ˆ๋‹ค.

data: () => ({
    latestTodos: [],
    latestDoneTodos: [],
    numDaysLabels: [],
    chartdata: {
      labels: [],
      datasets: [
        {
          label: "๐ŸŽฏ Created Todos",
          pointBackgroundColor: "#007bff",
          borderWidth: 1,
          pointBorderColor: "#007bff",
          borderColor: "#007bff",
          data: []
        },
        {
          label: "โœจ Completed Todos",
          pointBackgroundColor: "#E74D4E",
          borderWidth: 1,
          pointBorderColor: "#dc3545",
          borderColor: "#E74D4E",
          data: []
        }
      ]
    },
    options: {
      scales: {
        yAxes: [
          {
            ticks: {
              beginAtZero: true
            },
            gridLines: {
              display: true
            }
          }
        ],
        xAxes: [
          {
            grindLines: {
              display: false
            }
          }
        ]
      },
      legend: { display: true },
      responsive: true,
      maintainAspectRatio: false,
      hoverBorderWidth: 20
    }
  }),

chart.js ์˜ ๊ณต์‹ ๋ฌธ์„œ์—์„œ๋Š” mounted() ํ›…์—์„œ this.renderChart(this.chartdata, this.options)๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ๊ทธ๋ ค์ง€๋Š”๋ฐ props๋กœ ์ข€ ๋” ํ™œ์šฉ๋„๋ฅผ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค๊ณ  ๋‚˜์™€ ์žˆ์—ˆ์ง€๋งŒ, ์ปดํฌ๋„ŒํŠธ ํ•˜๋‚˜์—์„œ๋งŒ ์“ฐ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ”๋กœ ์˜ต์…˜ ์•ˆ์— data๋„ render ์šฉ ๋ฉ”์„œ๋“œ๋„ ๋‹ค ํ•œ ๋ฒˆ์— ์จ๋‘์—ˆ๋‹ค.

 

๋ฐ์ดํ„ฐ๋“ค์€ mounted ๋˜๊ธฐ ์ „ created() ํ›…์—์„œ ๋ชจ๋‘ ์ •์˜๋˜๊ณ , ์กฐ์ •๋  ํ•„์š”๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— created() ํ›…์—์„œ ์•„๋ž˜ ๊ฐ™์ด ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•ด์ฃผ์—ˆ๋‹ค.

 

created() {
    this.chartdata.labels = this.locateLabelsOfDays();
    this.latestTodos = this.getLatestTodos();
    this.latestDoneTodos = this.getLatestDoneTodos();
    this.chartdata.datasets[0].data = this.getTodosOfDay();
    this.chartdata.datasets[1].data = this.getDoneTodosOfDay();
  },

 

์ƒ‰์ธ ์—ญํ• ์„ ํ•˜๋Š” ์š”์ผ ๋ชฉ๋ก๋“ค์€ '์˜ค๋Š˜ ๋‚ ์งœ'๊ฐ€ ๊ฐ€์žฅ ์˜ค๋ฅธ์ชฝ์— ์œ„์น˜ํ•˜๋„๋ก ๋งค์ผ ๋งค์ผ ๋‹ฌ๋ผ์ ธ์•ผ ํ•˜๋ฏ€๋กœ, locateLabelsOfDays() ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ์ •์˜ํ•˜๊ณ , ์ตœ๊ทผ todos ๋‘ ๊ฐœ๋ฅผ ๋งŒ๋“ค์–ด์ค€ ๋’ค, ๊ฐ todos์˜ ๊ฐฏ์ˆ˜๋ฅผ ์š”์ผ์˜ index์™€ ์ƒ์‘ํ•˜๋„๋ก ๋งŒ๋“  ๋ฐฐ์—ด ๋ฐ์ดํ„ฐ๋ฅผ chartdata.datasets์˜ data์— ๊ฐ๊ฐ ์ฃผ์ž…ํ•ด์ฃผ์—ˆ๋‹ค.

 

๋™์ ์œผ๋กœ ๋ผ๋ฒจ ์ƒ์„ฑํ•˜๊ธฐ

 locateLabelsOfDays() {
      let labels = [];
      let numLabels = [];
      const today = new Date();
      const year = today.getFullYear();
      const month = today.getMonth();
      let day = today.getDate();
      while (labels.length < 7) {
        const labelOfDay = new Intl.DateTimeFormat("en-US", {
          weekday: "short"
        }).format(new Date(year, month, day));
        labels.unshift(labelOfDay);
        const numLabelOfDay = new Date(year, month, day).getDay();
        numLabels.unshift(numLabelOfDay);
        day--;
      }
      this.numDaysLabels = numLabels;
      return labels;
    },

Sun, Mon, Tue .. ๋“ฑ์˜ string์„ ์ด์šฉํ•ด label์„ ์ƒ์„ฑํ•  ์ˆ˜๋„ ์žˆ์—ˆ๊ฒ ์ง€๋งŒ, ๋‹ค์–‘ํ•œ Date ๊ฐ์ฒด ๊ด€๋ จ ๋ฉ”์„œ๋“œ๋ฅผ ์จ๋ณด๊ณ  ์‹ถ์–ด์„œ

new Intl.DateTimeFormat() ๋ฉ”์„œ๋“œ๋ฅผ ์ฐพ์•˜๋‹ค. ํ‘œ์ค€ ๋‚ด์žฅ ๊ฐ์ฒด๋กœ Intl.DateTimeFormat์€ ์–ธ์–ด ์„ค์ •์— ๋”ฐ๋ผ ๋‚ ์งœ์™€ ์‹œ๊ฐ„ ์„œ์‹์„ ์ง€์›ํ•œ๋‹ค. ์˜ต์…˜์œผ๋กœ ์„ธ๋ฐ€ํ•˜๊ฒŒ ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ํŒŒ์‹ฑํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‚˜๋Š” ์˜๋ฌธ์œผ๋กœ short ๋ฒ„์ „์˜ ์š”์ผ ์ด๋ฆ„์„ ์–ป๊ธฐ ์œ„ํ•ด "en-US", short ๋“ฑ์˜ ์˜ต์…˜์„ ๊ฐ€์กŒ์ง€๋งŒ, ํ•œ๊ธ€ ์š”์ผ ์ด๋ฆ„๋„ ๋ฌผ๋ก  ๊ฐ€์งˆ ์ˆ˜ ์žˆ๊ณ , long, medium ๋“ฑ์˜ ์˜ต์…˜์œผ๋กœ ๋ณด๋‹ค ๊ธด ์ด๋ฆ„์„ ์ถ”์ถœํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

 

MDN_Intl.DateTimeFormat

 

Intl.DateTimeFormat - JavaScript | MDN

Intl.DateTimeFormat์€ ์–ธ์–ด์— ๋งž๋Š” ๋‚ ์งœ ๋ฐ ์‹œ๊ฐ„ ์„œ์‹์„ ์ง€์›ํ•˜๋Š” ๊ฐ์ฒด์˜ ์ƒ์„ฑ์ž์ž…๋‹ˆ๋‹ค. dateStyle๊ณผ timeStyle ์˜ต์…˜์„ ํ†ตํ•ด ๋‚ ์งœ์™€ ์‹œ๊ฐ„ ํ˜•์‹์„ ๋น ๋ฅด๊ฒŒ ๋งž์ถœ ์ˆ˜ ์žˆ๊ณ , ๋” ์ž์„ธํ•œ ์กฐ์ •์„ ์œ„ํ•œ ๋‹ค๋ฅธ ์˜ต์…˜๋„

developer.mozilla.org

 

์˜ค๋Š˜ ๋‚ ์งœ๊ฐ€ ์ผ์š”์ผ์ด๋ผ๋ฉด, [์›”ํ™”์ˆ˜๋ชฉ๊ธˆํ† ์ผ] ์ˆœ์œผ๋กœ ์ตœ๊ทผ ๊ณผ๊ฑฐ ์š”์ผ์ด ๋ฉ€์ˆ˜๋ก ์™ผ์ชฝ์— ์œ„์น˜ํ•ด์•ผ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— unshift()๋กœ ๋ฐฐ์—ด์— ์›์†Œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๋Š” ๋ฐฉ๋ฒ•์„ ์ผ๋‹ค.

 

์ตœ๊ทผ ๋‚ ์งœ์˜ todos ๊ฐ–๊ณ  ์˜ค๊ธฐ

์œ„์—์„œ๋Š” created() ์‚ฌ์ดํด์—์„œ getLatesTodos๋ฅผ ๊ฐ€์ง€๊ณ  ์˜ค๋Š” ๋ฐฉ๋ฒ•์„ ์•ฝ๊ฐ„ ์ˆ˜์ •ํ•ด ์•„๋ž˜์ฒ˜๋Ÿผ ๊ฐœ์„ ํ–ˆ๋‹ค.

this.latestTodos = this.getLatesTodos("created");
this.latestDoneTodos = this.getLatesTodos("completed");

๋˜‘๊ฐ™์ด ์“ฐ์ธ ์ฝ”๋“œ๋ฅผ ์ •๋ฆฌํ•ด ํ•˜๋‚˜๋กœ ์žฌ์‚ฌ์šฉํ–ˆ๋‹ค. ๊ตฌ๋ถ„์€ String ์ธ์ž๋กœ ๋‘์—ˆ๋‹ค.

 

getLatesTodos(param) {
      let d = new Date();
      let day = d.getDate();
      const lastDateOfWeek = new Date(d.setDate(day - 7));
      if (param === "created") {
        return this.$store.state.todos.filter(
          todo =>
            new Date(todo.createdAt) <= new Date() &&
            new Date(todo.createdAt) >= lastDateOfWeek
        );
      } else {
        return this.$store.state.todos.filter(
          todo =>
            new Date(todo.completedAt) <= new Date() &&
            new Date(todo.completedAt) >= lastDateOfWeek
        );
      }
    },

์ผ์ฃผ์ผ ์ „์˜ ๋‚ ์งœ๋ฅผ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์ƒ๊ฐ๋ณด๋‹ค ๊ฐ„๋‹จํ–ˆ๋Š”๋ฐ setDate()๋ฅผ ์ด์šฉํ•ด์„œ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

์˜ค๋Š˜ ๋‚ ์งœ๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด new Date() ๊ฐ์ฒด๋ฅผ ๋ณ€์ˆ˜ d์— ๋‹ด๊ณ , ์š”์ผ์„ ์–ป์–ด day์— ๋‹ด๋Š”๋‹ค.

 

Date ๊ฐ์ฒด ๊ฐ’๋ผ๋ฆฌ์˜ ๋น„๊ต๋ฅผ ์œ„ํ•ด ์œ„์ฒ˜๋Ÿผ ๋ฐ˜ํ™˜๋œ ๊ฒฐ๊ณผ๋ฅผ ๋„ฃ์–ด Date ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. Date๋Š” ๋น„๊ต ์—ฐ์‚ฐ์ž๋ฅผ ํ†ตํ•ด ๋น„๊ต ๊ฐ€๋Šฅํ•˜๋‹ค.

? operand

์ด๋•Œ todo๊ฐ€ done ํ‘œ์‹œ๊ฐ€ ๋˜๊ธฐ๋งŒ ํ•˜๋ฉด completedAt ๋ฐ์ดํ„ฐ๊ฐ€ ์ƒ๊ฒจ๋ฒ„๋ ค์„œ, ์‚ฌ์šฉ์ž๊ฐ€ ์ทจ์†Œํ–ˆ๋‹ค๊ฐ€ ๋‹ค์‹œ pending todo ์ž๋ฆฌ๋กœ ์˜ฎ๊ฒผ์„ ๋•Œ์—๋„ ์—ฌ์ „ํžˆ ํ•ด๋‹น ๋ฐ์ดํ„ฐ๊ฐ€ ์ž”์กดํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋‹ค. ์ด๋•Œ๋Š” object์˜ completedAt ์†์„ฑ์„ delete๋กœ ์ง€์›Œ์ฃผ๊ธฐ๋งŒ ํ•˜๋ฉด ๋˜๋Š”๋ฐ, ์•„๋ž˜์ฒ˜๋Ÿผ typescript ์—๋Ÿฌ๊ฐ€ ๋‚ฌ๋‹ค.

 

the operand of 'delete' operator must be optional

 

์•Œ๊ณ ๋ณด๋‹ˆ Todo๋Š” ์•„๋ž˜์ฒ˜๋Ÿผ ํƒ€์ž…์ด ์„ ์–ธ๋œ ์ƒํƒœ์˜€๋Š”๋ฐ, completedAt์ด ๋นˆ ๊ฐ’์ผ ๊ฒฝ์šฐ๊ฐ€ ๊ณ ๋ ค๊ฐ€ ์•ˆ ๋˜์–ด ์žˆ์–ด์„œ์˜€๋‹ค.

 

interface Todo {
  title: string;
  isDone: boolean;
  isEditable: boolean;
  cate: string;
  createdAt: Date;
  completedAt: Date;
}

 

์œ„ ์ฝ”๋“œ์—์„œ completedAt ์†์„ฑ๋งŒ ์•„๋ž˜์ฒ˜๋Ÿผ ๋ฐ”๊ฟ”์ค€๋‹ค. ํ•ด๋‹น ์˜ค๋ฅ˜๊ฐ€ ์‚ฌ๋ผ์ง„๋‹ค.

completedAt?: Date;

 

์ด ๋ฌธ์ œ๋Š” ์ด ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ–ˆ๋‹ค.

datasets์˜ date ์ฑ„์šฐ๊ธฐ

์—ฌ๊ธฐ์„œ๋„ ์•„๊นŒ์ฒ˜๋Ÿผ ๋ฐ˜๋ณต๋˜๋Š” ํ•จ์ˆ˜๊ฐ€ ์žˆ์–ด์„œ ์ฝ”๋“œ ์ •๋ฆฌ๋ฅผ ํ•œ ๋ฒˆ ํ–ˆ๋‹ค.

this.chartdata.datasets[0].data = this.getTodosOfDay("createdAt");
this.chartdata.datasets[1].data = this.getTodosOfDay("completedAt");

์ธ์ž๋กœ ์ค€ string์€ ๋‚˜์ค‘์— todo์˜ ์†์„ฑ ์ด๋ฆ„์œผ๋กœ ๊ทธ๋Œ€๋กœ ์“ฐ์ผ ๊ฒƒ์ด๋ฏ€๋กœ ๋งž์ถ”๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

 

getTodosOfDay(param) {
      let LengthOftodos = this.latestTodos;
      let localNums = this.numDaysLabels.slice();
      for (let i = 0; i < localNums.length; i++) {
        let cnt = 0;
        LengthOftodos.forEach(todo => {
          const dayOfTodo = new Date(todo[param]).getDay();
          if (dayOfTodo === localNums[i]) cnt++;
        });
        localNums[i] = cnt;
      }
      return localNums;
    }

[param]์œผ๋กœ ๋œ ๋ถ€๋ถ„๋งŒ ์ œ์™ธํ•˜๋ฉด ๋™์ผํ•œ ์ฝ”๋“œ๋‚˜ ๋งˆ์ฐฌ๊ฐ€์ง€์˜€๋‹ค. Object์˜ ์†์„ฑ์— ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•์€ dot ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์จ์ฃผ๊ฑฐ๋‚˜ Object["property"]๋กœ ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. param์ด string ํƒ€์ž…์œผ๋กœ ๋“ค์–ด์˜ค๋ฏ€๋กœ todo[param]์œผ๋กœ ์ ์–ด์ฃผ๋ฉด ์กฐ๊ฑด์œผ๋กœ ๋ถ„๊ธฐํ•  ํ•„์š” ์—†์ด ์ฝ”๋“œ๊ฐ€ ๋”์šฑ ๊ฐ„๊ฒฐํ•ด์ง„๋‹ค.

 

์›๋ž˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋‘ ๊ฐœ๋กœ ๋‚˜๋ˆ  ์“ฐ๋ฉฐ ์ž„์‹œ ๋ฐฐ์—ด ์—ญํ• ์„ ํ•˜๋Š” numDaysLabels๋ฅผ ๋‘ ๋ฒˆ์— ๋‚˜๋ˆ  ์“ฐ๊ธฐ ์œ„ํ•ด slice() ํ•จ์ˆ˜๋กœ ๋ฐฐ์—ด์„ ๋ณต์‚ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ผ๋Š”๋ฐ, ์—ฌ๊ธฐ์„œ๋Š” ์‚ฌ์‹ค ๊ทธ๋Ÿด ํ•„์š”๊ฐ€ ์—†์–ด์„œ slice() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ญ์ œํ•ด๋„ ๋ฌด๋ฐฉํ•˜๋‹ค.

 

์œ„ ๋ฉ”์„œ๋“œ์—์„œ ์ค‘์š”ํ•œ ์ ์€ ๋ฐ์ดํ„ฐ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์„ ๋•Œ๋„ 0 ๊ฐ’์€ ๋ฌด์กฐ๊ฑด ๋„ฃ์–ด์ฃผ์–ด์•ผ ํ•œ๋‹ค๋Š” ์ ! ๊ทธ๋ž˜ํ”„๊ฐ€ ๋ง๊ฐ€์ง€์ง€ ์•Š๊ฒŒ ๋ฐ์ดํ„ฐ ๋ณด์ •์„ ์œ„ํ•ด์„œ์ด๋‹ค.

 

์ƒ๋Œ€์ ์œผ๋กœ ๊ฐ„๋‹จํ•œ Pie chart์— ๋น„ํ•ด ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€๊ณตํ•  ์ผ์ด ๋งŽ์•˜๋˜ ๋ถ€๋ถ„์ด๋ผ ๊ณต๋ถ€๊ฐ€ ๋งŽ์ด ๋๋‹ค. ์›๋ž˜๋Š” ์ง์ ‘ ๋ผ์ธ ์ฐจํŠธ๋ฅผ ๊ตฌํ˜„ํ•ด์„œ ํ•˜๋Š” ๊ฒƒ๊นŒ์ง€๊ฐ€ ๋ชฉํ‘œ์˜€๋Š”๋ฐ, ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ๋ชปํ•ด์„œ ์•„์‰ฌ์› ๋‹ค. ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”์— ๋Œ€ํ•œ ๊ด€์‹ฌ์ด ๊ณ„์† ๋†’์•„์ ธ์„œ, ์ฐจํŠธ๋‚˜ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋“ฑ์„ ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” ๊ณต๋ถ€๋Š” ์•ž์œผ๋กœ๋„ ๊ณ„์† ๊ด€์‹ฌ์žˆ๊ฒŒ ํ•ด๋‚˜๊ฐˆ ๊ฒƒ ๊ฐ™๋‹ค.

 

 

 

๐Ÿ’Œ LineChart.js ์ปดํฌ๋„ŒํŠธ์— ๋Œ€ํ•œ ์ „์ฒด ์†Œ์Šค๋Š” ์ด๊ณณ์—์„œ