AG Charts Core Library

13.2.1 · active · verified Tue Apr 21

ag-charts-core is a high-performance, fully-featured, and highly customizable canvas-based charting library for JavaScript and TypeScript applications. It provides advanced charting capabilities with a strong focus on performance, delivering smooth interactions and rendering. A key differentiator is its "no third-party dependencies" philosophy, making it a lightweight and self-contained solution compared to many alternatives. The library is currently at version 13.2.1 and maintains an active release cadence with frequent patch and minor updates, and significant API changes occurring with major versions, such as 13.0.0. It serves as the foundational charting engine for the broader AG Charts ecosystem, offering direct integrations and comprehensive examples for popular frameworks including React, Angular, and Vue.

Common errors

Warnings

Install

Imports

Quickstart

Initializes and renders a simple column and line chart displaying annual company spending and profit data using `AgCharts.create`.

import { AgCharts } from 'ag-charts-core';

interface DataItem {
  year: number;
  spending: number;
  profit: number;
}

const data: DataItem[] = [
  { year: 2020, spending: 1200, profit: 800 },
  { year: 2021, spending: 1500, profit: 950 },
  { year: 2022, spending: 1300, profit: 850 },
  { year: 2023, spending: 1700, profit: 1100 }
];

function createPerformanceChart() {
  const chartOptions = {
    container: document.getElementById('myChart') as HTMLElement,
    data: data,
    title: {
      text: 'Annual Company Performance',
    },
    subtitle: {
      text: 'Spending vs. Profit Analysis',
    },
    series: [
      {
        type: 'column',
        xKey: 'year',
        yKey: 'spending',
        yName: 'Spending',
        fill: '#5BC0DE',
        stroke: '#428BCA'
      },
      {
        type: 'line',
        xKey: 'year',
        yKey: 'profit',
        yName: 'Profit',
        stroke: '#F0AD4E',
        marker: {
          enabled: true,
          fill: '#F0AD4E'
        }
      }
    ],
    axes: [
      {
        type: 'category',
        position: 'bottom',
        title: {
          text: 'Year'
        }
      },
      {
        type: 'number',
        position: 'left',
        title: {
          text: 'Amount ($)'
        }
      }
    ]
  };

  AgCharts.create(chartOptions);
}

// Simulate DOMContentLoaded for demonstration purposes in a non-browser environment.
// In a browser, ensure this runs after the DOM is fully loaded.
if (typeof document !== 'undefined') {
  document.addEventListener('DOMContentLoaded', () => {
    let container = document.getElementById('myChart');
    if (!container) {
      container = document.createElement('div');
      container.id = 'myChart';
      container.style.width = '700px';
      container.style.height = '400px';
      document.body.appendChild(container);
    }
    createPerformanceChart();
  });
}

view raw JSON →