lightweight-charts
它能做什么
这个技能帮助 AI 智能体使用 Lightweight Charts 库创建和更新图表。适合在网页应用中制作价格图表或时间序列图表的开发者。
适用场景
- ✓当你想在网页中添加蜡烛图、折线图或柱状图时。
- ✓当你需要把实时或历史价格数据导入现有图表时。
- ✓当你想为图表添加标记、提示框、窗格或颜色时。
技能链接
https://github.com/tradingview/lightweight-charts/blob/master/.github/skills/lightweight-charts/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我看看如何使用 Lightweight Charts 添加带实时价格更新的蜡烛图。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会先检查你的项目使用的库版本,阅读其类型定义,然后用正确的选项名称编写代码。它会避免猜测不存在的方法。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Lightweight Charts skill
Works the same whether the project is a downstream npm consumer app or an upstream lightweight-charts source checkout. Detect which one you are in (below) and resolve every API name from whatever typings are locally available.
Source lookup order
Do not assume you are inside the upstream source repository.
- In a consumer app, inspect the installed package first:
node_modules/lightweight-charts/package.jsonfor the actual version.node_modules/lightweight-charts/dist/typings.d.tsfor the API surface.
- In the upstream repo, inspect
dist/typings.d.tsfirst, thensrc/if generated output is unavailable. - Use official docs/examples as supporting evidence, but local typings win when they disagree.
Verify before answering (copy-paste):
node -p "require('./node_modules/lightweight-charts/package.json').version"
rg -n "createSeriesMarkers|addSeries|IPrimitivePaneRenderer|createImageWatermark|createOptionsChart" node_modules/lightweight-charts/dist/typings.d.ts
# upstream checkout instead of a consumer app:
rg -n "createSeriesMarkers|IPrimitivePaneRenderer|createImageWatermark|createOptionsChart" dist/typings.d.ts src
If the relevant file is unavailable, say what could not be verified. Do not invent option names, methods, exports, or wrapper behavior.
If the user's code imports from lightweight_charts import ... (underscore), uses pandas/asyncio, or talks about a Python window wrapper, they are probably using the third-party Python wrapper rather than the TypeScript package. Say that clearly before giving core lightweight-charts v5 JavaScript advice.
Mental model
Eight layers, in dependency order. Most bugs come from confusing one for another:
- Chart —
createChart(container, options)returns anIChartApi. One chart per container element. - Series — added via
chart.addSeries(SeriesType, options, paneIndex?). Each call returns anISeriesApi. v5 requires importing the series type explicitly. - Scales —
chart.timeScale()(ITimeScaleApi),chart.priceScale(id)(IPriceScaleApi). Govern range, ticks, autoscale, visibility. - Data model — arrays of
{ time, … }points.Time = UTCTimestamp | BusinessDay | string.UTCTimestampis seconds, not milliseconds. Times must be unique and ascending per series. - Interaction —
chart.subscribeCrosshairMove,chart.subscribeClick,timeScale.subscribeVisibleLogicalRangeChange, etc. - Layout —
chart.panes(),chart.addPane(). Adding a series with an out-of-rangepaneIndexauto-creates the pane. - Extension — pane primitives, series primitives, custom series, watermarks, custom renderers (canvas via
fancy-canvas). - Wrappers — React/Vue/Web Components/iOS/Android. Lifecycle is the wrapper's responsibility; the core library is framework-agnostic.
v5 essentials
The conventions that catch people copying older snippets:
import { createChart, CandlestickSeries, LineSeries } from 'lightweight-charts';
const chart = createChart(container, { /* ChartOptions */ });
const candles = chart.addSeries(CandlestickSeries, { /* options */ });
candles.setData([
{ time: 1700000000, open: 1, high: 2, low: 0.5, close: 1.5 },
]);
Key v5 changes versus older snippets:
chart.addSeries(SeriesType, options, paneIndex?)replacesaddLineSeries/addCandlestickSeries/ …createSeriesMarkers(series, markers)replacesseries.setMarkers(...). The returned primitive owns.setMarkers(...)/.markers().createTextWatermark(pane, options)andcreateImageWatermark(pane, imageUrl, options)replace thewatermarkchart option.- Series types are tree-shaken — importing them is required for ESM.
If a snippet calls addLineSeries or series.setMarkers, it's v4 or older. Confirm the user's version before forwarding it.
When the task targets v5, show the v5 API directly — do not hedge by mixing in v4 syntax.
Triage (problem → API → avoid)
| User asks about | First check | Answer with | Avoid |
|---|---|---|---|
| v5 series creation | package version + typings | chart.addSeries(SeriesType, options) |
addLineSeries / addCandlestickSeries |
| markers | createSeriesMarkers export |
marker primitive + required color |
series.setMarkers |
| timezone | formatter need vs data semantics | Intl.DateTimeFormat in formatters |
fake timeScale.timezone |
| realtime updates | last-bar vs full replace | series.update(point) |
常见问题
智能体需要在我的项目中安装该库吗?
需要时效果最好,因为这样它能读取准确的版本和类型定义。必要时它也可以使用官方文档。
它能帮忙处理 React 或 Vue 的封装组件吗?
可以。该技能涵盖这些框架的封装选项。
如果智能体无法确认某个细节怎么办?
它会说明哪些内容无法核实,这样你就知道需要自己检查什么。
详情
作者的原始描述
Use when working with TradingView's lightweight-charts — creating charts, adding series (Line/Area/Bar/Candlestick/Histogram), configuring time and price scales, streaming realtime or historical data, panes, markers, per-bar/per-point colors, tooltips, coordinate conversion, custom plugins or primitives, non-financial horizontal scales, SSR/browser loading, or React/Vue/Web Components wrappers. Covers v5 API conventions and the common time, scale, marker, plugin, and wrapper foot-guns.
热度
- GitHub 星标
- 18k
- 排名
- #10735
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …