Lightweight Charts React Components

Lightweight Charts React Components

Guides an AI coding agent in building and fixing TradingView lightweight-charts in React: candlesticks, volume panes, live WebSocket data, tooltips, markers and synced charts.

Skill files11 files

references/

SKILL.md155 lines
1
---
2
name: lightweight-charts-react-components
3
description: lightweight-charts-react-components recipes for TradingView lightweight-charts in React. Candlestick, line, and area series; volume and indicator panes; realtime WebSocket updates; infinite history on scroll; crosshair OHLC legends and tooltips; trade markers and price lines; synchronized charts; numeric options and yield-curve axes. Use when adding or fixing a financial or trading chart in a React app, or when the user mentions lightweight-charts, TradingView charts in React, or this package.
4
license: MIT
5
metadata:
6
author: ukorvl
7
version: "1.0"
8
source: "https://github.com/ukorvl/lightweight-charts-react-components/tree/0368191127568e48aef6f7bda2ff3900e8e24756/skills/lightweight-charts-react-components"
9
---
10
11
# lightweight-charts-react-components guide
12
13
## Quick Start
14
15
Let the components manage chart and series creation and cleanup. Import components
16
and ref types from `lightweight-charts-react-components`; import native data, option,
17
and event types from `lightweight-charts`.
18
19
1. Check versions against the compatibility table below. Read declared ranges
20
from the app's `package.json`, then the installed versions from the `version`
21
field of `node_modules/<package>/package.json` for
22
`lightweight-charts-react-components`, `lightweight-charts`, `react`, and
23
`react-dom`. If the library is not installed, follow
24
[Installation](#installation). Ensure chart rendering runs in the browser,
25
within the app's client boundary.
26
2. For a basic static chart, start from the minimal chart below. Otherwise, read the
27
reference matching the requested behavior. Adapt its feed and UI; preserve its
28
data contract, component nesting, and API readiness handling.
29
3. Choose one data owner: pass the complete dataset through `data` for React-owned
30
updates, or use `reactive={false}` and the series API for frequent ticks.
31
32
### Installation
33
34
Install the wrapper together with its `lightweight-charts` peer dependency, using
35
the project's package manager. React and React DOM must already be installed.
36
37
```sh
38
npm install lightweight-charts-react-components lightweight-charts
39
```
40
41
### Minimal chart
42
43
```tsx
44
import type { LineData, UTCTimestamp } from "lightweight-charts";
45
import {
46
Chart,
47
LineSeries,
48
TimeScale,
49
TimeScaleFitContentTrigger,
50
} from "lightweight-charts-react-components";
51
52
// Data must be sorted ascending by time with unique times (UTC seconds here).
53
export function SimpleLineChart({ data }: { data: LineData<UTCTimestamp>[] }) {
54
return (
55
// autoSize follows the container, which needs a nonzero height.
56
<Chart
57
options={{ autoSize: true }}
58
containerProps={{ style: { height: 300, width: "100%" } }}
59
>
60
<LineSeries data={data} />
61
<TimeScale>
62
<TimeScaleFitContentTrigger deps={[]} />
63
</TimeScale>
64
</Chart>
65
);
66
}
67
```
68
69
## Examples and snippets (reference files)
70
71
Read the reference matching the user's outcome. Each contains a complete TypeScript
72
recipe, data and integration contracts, reasons for the architecture, failure modes,
73
and acceptance checks. Combine references when a task spans several outcomes; do
74
not load every reference for a simple chart.
75
76
| User request | Reference |
77
| ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
78
| WebSocket candles, updating the current bar, stale history, excessive chart renders | [Market data and live updates](references/market-data-and-live-updates.md) |
79
| Older history on scroll, viewport jumps, symbol/interval changes, late API responses | [History and range selection](references/history-and-range-selection.md) |
80
| Candles plus volume, moving averages, oscillator panes, independent price scales | [Price, volume, and indicators](references/price-volume-and-indicators.md) |
81
| OHLC legend, hover details, missing data, tooltip positioning | [Hover legends and tooltips](references/hover-legends-and-tooltips.md) |
82
| Executions and signals, stop/target levels, click-to-place price lines | [Trade markers and price levels](references/trade-markers-and-price-levels.md) |
83
| Compare assets with different prices, fixed-baseline returns, toggle comparisons | [Performance comparison](references/performance-comparison.md) |
84
| Separate charts that share scrolling, zooming, and a crosshair | [Synchronized charts](references/synchronized-charts.md) |
85
| Trading-session shading, pane backgrounds, custom drawing that follows zoom | [Session overlays and primitives](references/session-overlays-and-primitives.md) |
86
| Options strikes, yield maturities, choosing a numeric or custom horizontal axis | [Numeric axes and chart types](references/numeric-axes-and-chart-types.md) |
87
88
If no reference matches the request, tell the user that the skill has no recipe
89
for it. Then build the solution from the public components and the upstream
90
`lightweight-charts` API, applying the Quick Start rules and the edge cases below.
91
92
### Skill compatibility
93
94
The recipes are verified against the reference versions below. These are the
95
tested baseline, not the latest available releases.
96
97
If an installed version differs from the reference version, compare it with the
98
compatibility range. Inside the range, recipes apply as written. Outside it,
99
tell the user about the mismatch before writing code, because breaking API
100
changes can affect the recipes, and verify every API the recipe uses against
101
the installed package.
102
103
| Dependency or environment | Reference version | Compatibility range and checks |
104
| ------------------------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
105
| `lightweight-charts-react-components` | `2.6.1` | Recipe target: `>=2.6.1 <3`. Other versions require checking installed exports, chart API refs, and reactive data behavior before adapting a recipe. |
106
| `lightweight-charts` | `5.2.1` | Declared peer: `>=5.0.8 <6`. |
107
| React and React DOM | `19.2.6` | Declared peers: `>=18.2 <20`. Keep `react` and `react-dom` on matching versions and use the application's existing React instance. |
108
| Node.js | — | Package engines: `>=18.14.0`. The app's build tools can require a newer version. |
109
| Module system | ESM | ESM `import` entry only; there is no CommonJS `require` entry. |
110
| Rendering | Browser | Charts need the DOM and canvas. Render them on the client, never during server rendering. |
111
112
## Common edge cases
113
114
- **Chart sizing:** Put DOM styles on `containerProps` and give the chart a
115
nonzero height.
116
- **Required ancestors:** Headless chart children need a chart wrapper ancestor.
117
`Markers`, `PriceLine`, and `SeriesPrimitive` belong inside their series;
118
`PriceScale`, `Watermark`, and `PanePrimitive` require a `Pane`;
119
`TimeScaleFitContentTrigger` requires a `TimeScale`.
120
- **API refs and readiness:** Use `ref.current?.api()` for the native API and
121
`containerRef` for the div. For `Chart`, use `ChartApiRef<Time, IChartApi>`.
122
`.api()` can initially return null; follow the recipe's readiness step before
123
imperative setup.
124
- **Viewport resets:** To preserve scroll/zoom, keep the chart's key stable and
125
live/history updates out of fit-trigger dependencies. Fit on initial load or a
126
deliberate reset. See [range handling](references/history-and-range-selection.md).
127
- **Data updates:** Use `data` for React-owned updates, or `reactive={false}` and the
128
series API when per-tick React renders are measurably costly. Avoid mixing both.
129
Reactive `data` is always the complete dataset. With wrapper 2.6.1 and
130
Lightweight Charts 5.2.1, `series.data()` reconstructs candle and line objects;
131
the wrapper's earlier-item reference comparison therefore sends multi-bar tail
132
updates through `setData()`, even when React keeps earlier references stable.
133
Keep data immutable, but use the chart-owned `reactive={false}` recipe and
134
explicit `series.update(bar)` when incremental writes are required. See
135
[live updates](references/market-data-and-live-updates.md).
136
137
## Source
138
139
Adapted from [ukorvl/lightweight-charts-react-components](https://github.com/ukorvl/lightweight-charts-react-components/tree/0368191127568e48aef6f7bda2ff3900e8e24756/skills/lightweight-charts-react-components)
140
at commit `0368191127568e48aef6f7bda2ff3900e8e24756`. Original author: ukorvl.
141
The [MIT license](LICENSE) and all nine reference recipes are retained. Local
142
corrections in [live updates](references/market-data-and-live-updates.md) reject
143
malformed timestamps and explain the tested versions' reactive-update limitation;
144
[session overlays](references/session-overlays-and-primitives.md) clarifies the
145
primitive update callback.
146
The other seven references and MIT notice are unchanged. This catalog copy adds
147
source attribution and operational boundaries; it does not imply TradingView
148
endorsement.
149
150
Recipes generate application code and can change dependencies. Follow the user's
151
requested scope and the host's approval policy. Feed access belongs to the app's
152
separately authorized adapter; keep credentials out of client code. Trade markers
153
are visual annotations, not order execution or server-side alerts. Use synthetic
154
data for local checks and report browser/feed behavior that remains untested.
155

© ukorvl · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,332 prompts

More by @OpenSourceBuffGuy

See all
Nine Christmas portraits of one fluffy dog prompt image

Nine Christmas portraits of one fluffy dog

Makes a 3x3 grid of nine hyperrealistic Christmas portraits of the same dog from a reference photo, in trees, snow, studio and cozy indoor scenes.

image-prompt, nano-banana, reference-image, pet-portrait, christmas, holiday, animals, multi-panel, photorealistic, cinematic, soft-lighting, winter, cozy, social-media-graphic, invitation, vertical-format, vibrant-colors, dramatic-lighting, studio-lighting, for-families, pet-care, long-form, bokeh, food-photography

Lab teacher silences class as infected close in prompt image

Lab teacher silences class as infected close in

Generates a short realistic horror clip in a Japanese school science lab where a teacher and students hide silently from infected figures closing in, with sound-driven beats.

video-prompt, horror, cinematic, photorealistic, handheld, timed-beats, camera-movement, negative-prompt, guardrails, moody, short-film, seedance, for-filmmakers, for-content-creators, storytelling, thriller, dramatic-lighting, muted-colors, japan

Valentine's newspaper editorial portrait from your photo prompt image

Valentine's newspaper editorial portrait from your photo

Turns an uploaded face photo into a top-down Valentine's fashion editorial: red blazer, roses, heart balloons and a newspaper headline.

image-prompt, nano-banana, reference-image, face-reference, photo-editing, portrait, woman, fashion-shoot, editorial, valentines-day, photorealistic, studio-lighting, close-up, high-angle, film-grain, vibrant-colors, flowers, text-rendering, placeholders, fashion, holiday, soft-lighting, bokeh, vertical-format

Reviews

Loading reviews…

Discussion

Loading comments…