Convert Figma logo to code with AI

tradingview logolightweight-charts

Performant financial charts built with HTML5 canvas

9,289
1,604
9,289
107

Top Related Projects

📊 Interactive JavaScript Charts built on SVG

Highcharts JS, the JavaScript charting framework

16,856

Open-source JavaScript charting library behind Plotly and Dash

64,568

Simple HTML5 Charts using the <canvas> tag

108,427

Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:

Quick Overview

TradingView's Lightweight Charts is an open-source, high-performance financial charting library for creating interactive and customizable charts. It's designed to be fast, lightweight, and easy to integrate into web applications, making it ideal for displaying financial data such as stock prices, cryptocurrencies, and other time series data.

Pros

  • Lightweight and fast performance, optimized for handling large datasets
  • Highly customizable with a wide range of chart types and styling options
  • Responsive design, suitable for both desktop and mobile applications
  • Active development and community support

Cons

  • Limited documentation compared to some other charting libraries
  • Steeper learning curve for advanced customizations
  • Primarily focused on financial charts, may not be as versatile for other types of data visualization
  • Some advanced features require a paid TradingView subscription

Code Examples

Creating a basic candlestick chart:

import { createChart } from 'lightweight-charts';

const chart = createChart(document.body, { width: 400, height: 300 });
const candlestickSeries = chart.addCandlestickSeries();

candlestickSeries.setData([
    { time: '2018-12-22', open: 75.16, high: 82.84, low: 36.16, close: 45.72 },
    { time: '2018-12-23', open: 45.12, high: 53.90, low: 45.12, close: 48.09 },
    { time: '2018-12-24', open: 60.71, high: 60.71, low: 53.39, close: 59.29 },
]);

Adding a moving average overlay:

const sma = chart.addLineSeries({
    color: 'rgba(4, 111, 232, 1)',
    lineWidth: 2,
});

sma.setData([
    { time: '2018-12-22', value: 27.58 },
    { time: '2018-12-23', value: 33.84 },
    { time: '2018-12-24', value: 39.92 },
]);

Customizing chart appearance:

chart.applyOptions({
    layout: {
        backgroundColor: '#ffffff',
        textColor: '#333',
    },
    grid: {
        vertLines: {
            color: 'rgba(70, 130, 180, 0.5)',
            style: 1,
            visible: true,
        },
        horzLines: {
            color: 'rgba(70, 130, 180, 0.5)',
            style: 1,
            visible: true,
        },
    },
});

Getting Started

To get started with Lightweight Charts, follow these steps:

  1. Install the library using npm:

    npm install lightweight-charts
    
  2. Import the library in your JavaScript file:

    import { createChart } from 'lightweight-charts';
    
  3. Create a chart and add a series:

    const chart = createChart(document.getElementById('chart'), { width: 400, height: 300 });
    const lineSeries = chart.addLineSeries();
    lineSeries.setData([
        { time: '2019-04-11', value: 80.01 },
        { time: '2019-04-12', value: 96.63 },
        { time: '2019-04-13', value: 76.64 },
    ]);
    
  4. Customize the chart as needed using the available options and methods.

Competitor Comparisons

📊 Interactive JavaScript Charts built on SVG

Pros of ApexCharts

  • More diverse chart types and customization options
  • Built-in responsiveness and animation features
  • Extensive documentation and examples

Cons of ApexCharts

  • Larger file size and potentially slower performance
  • Less specialized for financial/trading charts

Code Comparison

ApexCharts:

var options = {
  chart: { type: 'line' },
  series: [{ data: [30,40,35,50,49,60,70] }],
  xaxis: { categories: [1991,1992,1993,1994,1995,1996,1997] }
};
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();

Lightweight Charts:

const chart = createChart(document.body, { width: 400, height: 300 });
const lineSeries = chart.addLineSeries();
lineSeries.setData([
  { time: '2019-04-11', value: 80.01 },
  { time: '2019-04-12', value: 96.63 },
  { time: '2019-04-13', value: 76.64 }
]);

ApexCharts offers a wide range of chart types and customization options, making it suitable for various data visualization needs. It includes built-in responsiveness and animations, enhancing the user experience. The extensive documentation and examples make it easier for developers to implement and customize charts.

However, ApexCharts has a larger file size compared to Lightweight Charts, which may impact load times and performance, especially for simpler charts. Additionally, while ApexCharts supports financial charts, it's not as specialized in this area as Lightweight Charts, which is specifically designed for financial and trading applications.

The code comparison shows that ApexCharts uses a more configuration-based approach, while Lightweight Charts employs a more programmatic style. ApexCharts requires more initial setup but offers more built-in features, whereas Lightweight Charts provides a simpler API for basic chart creation.

Highcharts JS, the JavaScript charting framework

Pros of Highcharts

  • More comprehensive and feature-rich, offering a wide range of chart types and customization options
  • Extensive documentation and community support
  • Cross-browser compatibility and responsive design out of the box

Cons of Highcharts

  • Larger file size and potentially slower performance for simple charts
  • Commercial license required for most use cases
  • Steeper learning curve due to its extensive API and options

Code Comparison

Lightweight Charts:

const chart = LightweightCharts.createChart(document.body, { width: 400, height: 300 });
const lineSeries = chart.addLineSeries();
lineSeries.setData([
    { time: '2019-04-11', value: 80.01 },
    { time: '2019-04-12', value: 96.63 },
]);

Highcharts:

Highcharts.chart('container', {
    series: [{
        data: [80.01, 96.63]
    }],
    xAxis: {
        categories: ['2019-04-11', '2019-04-12']
    }
});

Both libraries offer straightforward ways to create basic charts, but Highcharts requires more configuration for advanced features. Lightweight Charts focuses on performance and simplicity for financial charts, while Highcharts provides a broader range of chart types and customization options.

16,856

Open-source JavaScript charting library behind Plotly and Dash

Pros of plotly.js

  • More versatile, supporting a wide range of chart types beyond financial charts
  • Extensive customization options and interactivity features
  • Large community and extensive documentation

Cons of plotly.js

  • Larger file size and potentially slower performance for simple charts
  • Steeper learning curve due to its extensive feature set
  • May be overkill for projects focused solely on financial charting

Code Comparison

lightweight-charts:

const chart = createChart(document.body, { width: 400, height: 300 });
const lineSeries = chart.addLineSeries();
lineSeries.setData([
    { time: '2019-04-11', value: 80.01 },
    { time: '2019-04-12', value: 96.63 },
    { time: '2019-04-13', value: 76.64 }
]);

plotly.js:

Plotly.newPlot('myDiv', [{
    x: ['2019-04-11', '2019-04-12', '2019-04-13'],
    y: [80.01, 96.63, 76.64],
    type: 'scatter'
}], {
    width: 400, height: 300
});

Both libraries offer straightforward ways to create charts, but lightweight-charts is more focused on financial data representation, while plotly.js provides a more general-purpose charting solution.

64,568

Simple HTML5 Charts using the <canvas> tag

Pros of Chart.js

  • More versatile with a wide range of chart types (line, bar, pie, etc.)
  • Extensive documentation and large community support
  • Easy to customize and animate charts

Cons of Chart.js

  • Larger file size, which may impact page load times
  • Less specialized for financial/trading charts
  • May require more setup for complex financial visualizations

Code Comparison

Chart.js:

new Chart(ctx, {
    type: 'line',
    data: {
        labels: ['Jan', 'Feb', 'Mar'],
        datasets: [{
            data: [10, 20, 30]
        }]
    }
});

Lightweight Charts:

const chart = LightweightCharts.createChart(container);
const lineSeries = chart.addLineSeries();
lineSeries.setData([
    { time: '2019-01-01', value: 10 },
    { time: '2019-02-01', value: 20 },
    { time: '2019-03-01', value: 30 }
]);

Summary

Chart.js is a versatile charting library suitable for various chart types and general-purpose data visualization. It offers extensive customization options and community support. However, it may be overkill for specialized financial charting needs and has a larger file size.

Lightweight Charts, on the other hand, is specifically designed for financial and trading charts, offering better performance and a smaller footprint. It may be more suitable for projects focused on stock market or trading data visualization but lacks the variety of chart types found in Chart.js.

108,427

Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:

Pros of d3

  • Highly flexible and customizable for creating a wide range of data visualizations
  • Large ecosystem with numerous extensions and plugins
  • Extensive documentation and community support

Cons of d3

  • Steeper learning curve, especially for complex visualizations
  • Requires more code to create basic charts compared to specialized libraries
  • Performance can be an issue with large datasets or complex animations

Code Comparison

d3:

const svg = d3.select("body").append("svg")
    .attr("width", 400)
    .attr("height", 300);

svg.append("rect")
    .attr("width", 400)
    .attr("height", 300)
    .attr("fill", "steelblue");

lightweight-charts:

const chart = LightweightCharts.createChart(document.body, {
    width: 400,
    height: 300
});

const lineSeries = chart.addLineSeries();
lineSeries.setData([
    { time: '2019-04-11', value: 80.01 },
    { time: '2019-04-12', value: 96.63 }
]);

The d3 example demonstrates creating a basic SVG element, while the lightweight-charts example shows how to create a simple line chart. d3 requires more low-level manipulation, whereas lightweight-charts provides higher-level abstractions for financial charts.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Lightweight Charts™

CircleCI npm version npm bundle size Dependencies count Downloads

Demos | Documentation | Discord community | Reddit

TradingView Lightweight Charts™ are one of the smallest and fastest financial HTML5 charts.

The Lightweight Charts™ library is the best choice for you if you want to display financial data as an interactive chart on your web page without affecting your web page loading speed and performance.

It is the best choice for you if you want to replace static image charts with interactive ones. The size of the library is close to static images but if you have dozens of image charts on a web page then using this library can make the size of your web page smaller.

Installing

es6 via npm

npm install lightweight-charts
import { createChart } from 'lightweight-charts';

const chart = createChart(document.body, { width: 400, height: 300 });
const lineSeries = chart.addLineSeries();
lineSeries.setData([
    { time: '2019-04-11', value: 80.01 },
    { time: '2019-04-12', value: 96.63 },
    { time: '2019-04-13', value: 76.64 },
    { time: '2019-04-14', value: 81.89 },
    { time: '2019-04-15', value: 74.43 },
    { time: '2019-04-16', value: 80.01 },
    { time: '2019-04-17', value: 96.63 },
    { time: '2019-04-18', value: 76.64 },
    { time: '2019-04-19', value: 81.89 },
    { time: '2019-04-20', value: 74.43 },
]);

CDN

You can use unpkg:

https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js

The standalone version creates window.LightweightCharts object with all exports from esm version:

const chart = LightweightCharts.createChart(document.body, { width: 400, height: 300 });
const lineSeries = chart.addLineSeries();
lineSeries.setData([
    { time: '2019-04-11', value: 80.01 },
    { time: '2019-04-12', value: 96.63 },
    { time: '2019-04-13', value: 76.64 },
    { time: '2019-04-14', value: 81.89 },
    { time: '2019-04-15', value: 74.43 },
    { time: '2019-04-16', value: 80.01 },
    { time: '2019-04-17', value: 96.63 },
    { time: '2019-04-18', value: 76.64 },
    { time: '2019-04-19', value: 81.89 },
    { time: '2019-04-20', value: 74.43 },
]);

Build Variants

Dependencies includedModeES moduleCommonJS ⚠️IIFE (window.LightweightCharts)
NoPRODlightweight-charts.production.mjslightweight-charts.production.cjsN/A
NoDEVlightweight-charts.development.mjslightweight-charts.development.cjsN/A
Yes (standalone)PRODlightweight-charts.standalone.production.mjs-lightweight-charts.standalone.production.js
Yes (standalone)DEVlightweight-charts.standalone.development.mjs-lightweight-charts.standalone.development.js

⚠️ Deprecation note: CommonJS support will be removed from the library at the start of 2024.

Development

See BUILDING.md for instructions on how to build lightweight-charts from source.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License. You may obtain a copy of the License at LICENSE file. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This software incorporates several parts of tslib (https://github.com/Microsoft/tslib, (c) Microsoft Corporation) that are covered by BSD Zero Clause License.

This license requires specifying TradingView as the product creator. You shall add the "attribution notice" from the NOTICE file and a link to https://www.tradingview.com/ to the page of your website or mobile application that is available to your users. As thanks for creating this product, we'd be grateful if you add it in a prominent place. You can use the attributionLogo chart option for displaying an appropriate link to https://www.tradingview.com/ on the chart itself, which will satisfy the link requirement.

NPM DownloadsLast 30 Days