Use Cases

How to Implement Data Visualization: Claude Code 활용 가이드

implement data visualization: Claude Code 활용. 실용적인 코드 예시와 단계별 가이드를 포함합니다.

Building Charts Efficiently with Claude Code

Data visualization is essential for web apps, but memorizing the API specifications for Chart.js or D3.js is a challenge. With Claude Code, you can simply describe what kind of chart you want, and get working code immediately.

Building a Dashboard with Chart.js

You can generate a sales dashboard using Chart.js with the following prompt.

> Create a monthly sales dashboard component in React using Chart.js.
> Make it switchable between bar chart and line chart.

Example generated code:

import { useState } from "react";
import {
  Chart as ChartJS,
  CategoryScale,
  LinearScale,
  BarElement,
  LineElement,
  PointElement,
  Title,
  Tooltip,
  Legend,
} from "chart.js";
import { Bar, Line } from "react-chartjs-2";

ChartJS.register(
  CategoryScale, LinearScale, BarElement,
  LineElement, PointElement, Title, Tooltip, Legend
);

const salesData = {
  labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
  datasets: [
    {
      label: "Sales ($K)",
      data: [120, 190, 150, 210, 180, 250],
      backgroundColor: "rgba(99, 102, 241, 0.5)",
      borderColor: "rgb(99, 102, 241)",
      borderWidth: 2,
    },
  ],
};

const options = {
  responsive: true,
  plugins: {
    legend: { position: "top" as const },
    title: { display: true, text: "Monthly Sales Report" },
  },
};

export function SalesDashboard() {
  const [chartType, setChartType] = useState<"bar" | "line">("bar");

  return (
    <div className="p-4">
      <div className="mb-4 flex gap-2">
        <button
          onClick={() => setChartType("bar")}
          className={chartType === "bar" ? "btn-active" : "btn"}
        >
          Bar Chart
        </button>
        <button
          onClick={() => setChartType("line")}
          className={chartType === "line" ? "btn-active" : "btn"}
        >
          Line Chart
        </button>
      </div>
      {chartType === "bar" ? (
        <Bar data={salesData} options={options} />
      ) : (
        <Line data={salesData} options={options} />
      )}
    </div>
  );
}

Real-Time Data Visualization

It’s also easy to implement real-time chart updates with data fetched from an API.

import { useEffect, useRef } from "react";
import { Chart } from "chart.js/auto";

export function RealtimeChart({ endpoint }: { endpoint: string }) {
  const canvasRef = useRef<HTMLCanvasElement>(null);
  const chartRef = useRef<Chart | null>(null);

  useEffect(() => {
    if (!canvasRef.current) return;

    chartRef.current = new Chart(canvasRef.current, {
      type: "line",
      data: {
        labels: [],
        datasets: [{
          label: "Real-time Data",
          data: [],
          borderColor: "rgb(34, 197, 94)",
          tension: 0.3,
        }],
      },
      options: {
        animation: { duration: 300 },
        scales: { x: { display: true }, y: { beginAtZero: true } },
      },
    });

    const interval = setInterval(async () => {
      const res = await fetch(endpoint);
      const { value, timestamp } = await res.json();
      const chart = chartRef.current;
      if (!chart) return;

      chart.data.labels!.push(timestamp);
      chart.data.datasets[0].data.push(value);

      // Show only the last 20 entries
      if (chart.data.labels!.length > 20) {
        chart.data.labels!.shift();
        chart.data.datasets[0].data.shift();
      }
      chart.update();
    }, 2000);

    return () => {
      clearInterval(interval);
      chartRef.current?.destroy();
    };
  }, [endpoint]);

  return <canvas ref={canvasRef} />;
}

Auto-Generating Charts from CSV Data

When you ask Claude Code to “create a feature that displays a chart from an uploaded CSV file,” it implements everything from file reading to parsing and display.

function csvToChartData(csv: string) {
  const lines = csv.trim().split("\n");
  const headers = lines[0].split(",");
  const labels = lines.slice(1).map((line) => line.split(",")[0]);

  const datasets = headers.slice(1).map((header, i) => ({
    label: header,
    data: lines.slice(1).map((line) => parseFloat(line.split(",")[i + 1])),
    borderColor: `hsl(${i * 60}, 70%, 50%)`,
    backgroundColor: `hsla(${i * 60}, 70%, 50%, 0.2)`,
  }));

  return { labels, datasets };
}

For effective prompt writing, see 5 Tips for Better Prompts. For productivity techniques with Claude Code, check out 10 Tips to 3x Your Productivity.

정리

Claude Code dramatically speeds up data visualization implementation. From Chart.js configuration to data transformation logic and interactive features, you get working code just by describing your requirements.

For more details, refer to the Claude Code official documentation.

#Claude Code #data visualization #Chart.js #charts #frontend
무료 제공

무료 PDF: 5분 완성 Claude Code 치트시트

이메일 주소만 등록하시면 A4 한 장짜리 치트시트 PDF를 즉시 보내드립니다.

개인정보는 엄격하게 관리하며 스팸은 보내지 않습니다.

Masa

이 글을 작성한 사람

Masa

Claude Code를 적극 활용하는 엔지니어. 10개 언어, 2,000페이지 이상의 테크 미디어 claudecode-lab.com을 운영 중.