TOAST UI Chart Documentation

repository·main·Indexed 26 days ago

https://github.com/nhn/tui.chart

A statistical data visualization library for creating customizable charts. It provides a core JavaScript package (@toast-ui/chart) and specialized wrappers for React (@toast-ui/react-chart) and Vue (@toast-ui/vue-chart). Supports a wide range of chart types including line-based, bar-based, statistical/distribution (BoxPlot, Treemap, Heatmap, Scatter), and circular/radial (Pie, Radar) charts.

Tokens
69.4K
Snippets
219
Records
284
Agent score
88%

What's inside TOAST UI Chart

  1. Overview of TOAST UI Chart packages

    main

    TOAST UI Chart is a statistical data visualization library that provides beautiful and customizable charts. It is available in three main flavors depending on your project's environment:

    • Plain JavaScript: The core component (@toast-ui/chart).
    • React: A wrapper component for React applications (@toast-ui/react-chart).
    • Vue: A wrapper component for Vue applications (@toast-ui/vue-chart).
  2. Key features of TOAST UI Chart

    main

    TOAST UI Chart includes several powerful features for data visualization:

    • Responsive: Use the responsive option to adjust chart options and animations based on the container size.
    • Zoomable: Enable zooming for Line, Area, and Treemap charts using the zoomable option.
    • Live Update: Manage real-time data updates using the addData API combined with the options.series.shift option.
    • Synchronized Tooltips: Synchronize tooltip displays across charts using the showTooltip API and the on custom event.
  3. Understand Legend types in TOAST UI Chart

    main

    TOAST UI Chart provides three types of legends depending on the chart type being used:

    1. Basic Legend: Consists of a checkbox, a color icon, and the series name. It is compatible with most charts (Line, Area, Bar, etc.) but not Heatmap or Treemap charts.
      • Clicking the checkbox toggles the visibility of the selected series.
      • Clicking the series name focuses the chart on that specific series.
    2. Spectrum Legend: Used for charts that utilize a colorValue (like Heatmap and Treemap). It displays an index representing relative levels within the chart.
    3. Circle Legend: Used specifically for Bubble charts to provide an index for circle size. It displays the largest value and provides 0.5x and 0.25x radius indicators.
  4. Create a LineScatter Chart

    main

    You can create a LineScatter chart using either the LineScatterChart constructor or the static lineScatterChart method from the Chart class. Both methods require an object containing el (the HTML element), data, and options. It is recommended to use an empty HTML element as the container to avoid unintended side effects.

    import { LineScatterChart } from '@toast-ui/chart';
    
    const chart = new LineScatterChart({
      el, 
      data, 
      options
    });
    
    // or
    
    import Chart from '@toast-ui/chart';
    
    const chart = Chart.lineScatterChart({
      el, 
      data, 
      options
    });
  5. Migrate from v3.x to v4.0: NestedPie Chart (formerly Combo Chart)

    main

    The Pie & Donut Combo Chart from v3.x is now the NestedPieChart in v4.0. It supports multiple nested levels. Data is structured using a series array where child elements use parentName to link to a previous element's name.

    const data = {
      series: [
        {
          name: 'browsers',
          data: [{ name: 'Chrome', data: 50 }],
        },
        {
          name: 'versions',
          data: [{ name: 'Chrome 64', parentName: 'Chrome', data: 40 }],
        }
      ],
    };
    
    const options = {
      series: {
        browsers: {},
        versions: {}
      }
    };
    
    Chart.nestedPieChart({el, data, options});
  6. Migrate from v3.x to v4.0: Package and Namespace Changes

    main

    When upgrading to v4.0, several fundamental changes in package naming and namespaces must be addressed:

    Package Name Change

    The package has moved to a scoped name. Replace tui-chart with @toast-ui/chart.

    Installation:

    # v3.x
    npm install tui-chart
    
    # v4.0
    npm install @toast-ui/chart

    Note: Ensure you uninstall tui-chart before installing @toast-ui/chart to avoid duplicates.

    Import Changes

    Update your import statements to use the new scoped package name.

    ES6 Modules:

    // v3.x
    import Chart from 'tui-chart';
    
    // v4.0
    import Chart from '@toast-ui/chart';
    // Or import specific charts for smaller bundles
    import { BarChart } from '@toast-ui/chart';

    CommonJS:

    // v3.x
    const Chart = require('tui-chart');
    
    // v4.0
    const Chart = require('@toast-ui/chart');

    Namespace Change

    The global namespace has changed from tui to toastui.

    Browser Usage:

    // v3.x
    const chart = tui.Chart.barChart(el, data, options);
    
    // v4.0
    const chart = toastui.Chart.barChart({el, data, options});
    import { BarChart } from '@toast-ui/chart';
  7. Migrate from v3.x to v4.0: Data Label Options

    main

    Data labels in v4.0 are significantly more powerful. Instead of a simple showLabel: true boolean, you now use a dataLabels object within the series configuration to control visibility, offsets, and formatting.

    const options = {
      series: {
        dataLabels: {
          visible: true,
          offsetX: 0,
          offsetY: 0,
          formatter: (value) => `$${value}`
        }
      }
    };
  8. Configure common chart components and options

    main

    TOAST UI Chart provides several common components and configuration options that apply across different chart types:

    Components

    • Export menu: For exporting chart data/images.
    • Legend: To display series labels.
    • Plot: Configuration for the plotting area.
    • Axes: Configuration for X and Y axes.
    • Tooltip: Configuration for data hover information.
    • No Data Text: Customizing the message shown when no data is present.

    Configuration Options

    • API introduction: Overview of the public API surface.
    • Common component theme: Styling components using themes.
    • chart options: Core configuration for the chart instance.
    • Layout Configuration: Managing the spatial arrangement of elements.
    • Live Update options: Configuring how charts behave during real-time data updates.
    • responsive options: Managing chart behavior across different screen sizes.
  9. Migrate from v3.x to v4.0: Installation and Package Names

    main

    In v4.0, the package name has changed from tui-chart to the scoped package @toast-ui/chart. To migrate, you must uninstall the old package and install the new one to prevent duplicate installations.

    Important: You must also update your import statements to use the new package name.

  10. Create a NestedPie Chart

    main

    You can create a NestedPieChart instance using either the NestedPieChart constructor or the static Chart.nestedPieChart method. Both methods require an object containing el (the HTML element to draw in), data, and options.

    Note: It is recommended to use an empty HTML element as the target el to prevent existing child elements from unintentionally affecting the chart.

    import { NestedPieChart } from '@toast-ui/chart';
    
    const chart = new NestedPieChart({el, data, options});
    
    // or
    
    import Chart from '@toast-ui/chart';
    
    const chart = Chart.nestedPieChart({el, data, options});
  11. Configure various chart types

    main

    TOAST UI Chart supports a wide variety of chart types. Documentation is available for each specific type to guide implementation and configuration:

    • Line-based: Line Chart, Area Chart, LineArea Chart
    • Bar-based: Bar Chart, Column Chart, ColumnLine Chart, Bullet Chart
    • Statistical/Distribution: BoxPlot Chart, Treemap Chart, Heatmap Chart, Scatter Chart, LineScatter Chart, Bubble Chart
    • Circular/Radial: Pie Chart, NestedPie Chart, Radar Chart, RadialBar Chart, Gauge Chart