WU
wuhan005/hugo-trading-chart
Lightweight, interactive charting component for Hugo static sites
hugo-trading-chart
TL;DR
hugo-trading-chart is a lightweight, interactive charting component for Hugo static sites. It allows you to display professional-grade stock trading charts (candlestick or area) with custom markers for buy/sell points and cost lines. It is built on top of Lightweight Charts and includes a Go utility to fetch historical data from Longport.
Installation
Step 1: Fetch Stock Chart Data
This project includes a Go utility to fetch historical stock data from Longport.
- Prerequisites: You need a Longport account and API credentials (App Key, App Secret, Access Token).
- Setup:
Navigate to thefetch-chart-datadirectory:Set your Longport credentials as environment variables (refer tocd fetch-chart-dataopenapi-godocumentation for details):export LONGPORT_APP_KEY="your_app_key" export LONGPORT_APP_SECRET="your_app_secret" export LONGPORT_ACCESS_TOKEN="your_access_token"
- Fetch Data:
Run the tool to download data. For example, to fetch NVIDIA (NVDA.US) data for Jan 2025:Note: Ensure the output directory (e.g.,go run main.go \ -symbol NVDA.US \ -start 2025-01-01 \ -end 2025-01-31 \ -output ../static/data/NVDA.json
../static/data/) exists.
Step 2: Configure Hugo
Integrate the chart component into your Hugo project.
- Copy Assets:
Copyassets/js/trading-chart.jsto your Hugo project'sassets/js/directory. - Copy Shortcode:
Copytrading-chart.htmlto your Hugo project'slayouts/shortcodes/directory.
Usage
Use the trading-chart shortcode in your Markdown content.
Basic Example
{{< trading-chart
data="/data/NVDA.json"
symbol="NVDA"
name="NVIDIA Corp."
>}}Advanced Example (with Markers)
You can add buy/sell markers and cost lines using the markers parameter.
{{< trading-chart
data="/data/AAPL.json"
symbol="AAPL"
name="Apple Inc."
type="candlestick"
height="500px"
markers=[
{"time": 1739285640, "price": 229.85, "text": "B", "position": "below", "color": "#ef5350", "costLine": true},
{"type": "priceLine", "price": 240.00, "title": "Target", "color": "#26a69a"}
]
>}}Parameters
| Parameter | Description | Default |
|---|---|---|
data |
Path to the JSON data file (relative to site root). | Required |
symbol |
Stock symbol to display (e.g., "AAPL"). | "STOCK" |
name |
Full name of the stock (e.g., "Apple Inc."). | "" |
type |
Chart type: "area" or "candlestick". |
"area" |
height |
Height of the chart container (CSS value). | "400px" |
markers |
JSON string defining markers and lines. | "[]" |
License
MIT License
On this page
Languages
JavaScript61.0%HTML32.6%Go6.4%
Contributors
MIT License
Created January 29, 2026
Updated February 1, 2026
