Build and export charts
Try it in Python
Save a standalone HTML chart with price, volume and indicator controls.
from pricegenerator import Chart, Generate, GenerationConfig
candles = Generate(GenerationConfig(seed=42, horizon=120))
Chart(candles, "candles.html", analysis=True, view=False)pricegenerator.rendering.api
Prepare a chart once, then save an interactive HTML document or a static image, or display it in a notebook. Request analysis explicitly when you need indicator controls and summary statistics.
PrepareChart
Create a validated ChartSpec from an OHLCV DataFrame. Set analysis=True to include summary statistics and switchable historical overlays. A ChartSpec input can be reused as is or copied with changed display settings. Analysis requires the source table.
PrepareChart(data, *, analysis: bool = False, **options) -> ChartSpec
Parameters (3)
data- An OHLCV pandas DataFrame or a previously prepared ChartSpec. The table is required when analysis=True.
analysis- Set True when supplying OHLCV data to include grouped technical indicators and statistics for the full input series. False produces the basic chart.
options- For an OHLCV DataFrame, pass FromDataFrame options such as title, theme or markers. For an existing ChartSpec, pass the specification fields to replace.
Chart
Save a chart and return its Path. HTML is interactive and opens in a browser by default. Set view=False for batch jobs. Omitting output creates a temporary HTML file. SVG, PNG and JPEG require an explicit path, and PNG/JPEG require pricegenerator[export]. Set analysis=True on an OHLCV table for indicators and statistics.
Chart(
data,
output: str | Path | None = None,
*,
format: str | None = None,
view: bool | None = None,
quality: int = 90,
analysis: bool = False,
markdown_report: str | Path | None = None,
**options,
) -> Path
Parameters (8)
data- An OHLCV pandas DataFrame or a previously prepared ChartSpec. The table is required when analysis=True.
output- Destination path for the chart. The suffix selects the format unless format is explicit. Omitting the path creates a temporary HTML file.
format- File format, html, svg, png or jpeg. The htm and jpg aliases are accepted. An explicit format must agree with the output filename suffix, if present.
view- Whether to open the saved chart in the default browser. None opens HTML automatically and leaves static formats on disk. Set False for unattended runs.
quality- JPEG encoding quality from 1 to 95 inclusive, as an integer. The default is 90.
analysis- Set True when supplying OHLCV data to include grouped technical indicators and statistics for the full input series. False produces the basic chart.
markdown_report- Optional path for the chart title and summary in Markdown. When a chart output path is supplied, use a different file for the report.
options- For an OHLCV DataFrame, pass FromDataFrame options such as title, theme or markers. For an existing ChartSpec, pass the specification fields to replace.
DisplayChart
Display an OHLCV table or an existing ChartSpec in a notebook with pricegenerator[notebook] installed. The default HTML view is interactive. Choose format="svg" for a static chart. Returns the result of IPython.display.display, normally a display handle in Jupyter.
DisplayChart(data, *, format: str = 'html', analysis: bool = False, **options)
Parameters (4)
data- An OHLCV pandas DataFrame or a previously prepared ChartSpec. The table is required when analysis=True.
format- Notebook output type. Use html for an interactive view or svg for a static vector graphic.
analysis- Set True when supplying OHLCV data to include grouped technical indicators and statistics for the full input series. False produces the basic chart.
options- For an OHLCV DataFrame, pass FromDataFrame options such as title, theme or markers. For an existing ChartSpec, pass the specification fields to replace.
pricegenerator.rendering.adapters
Convert a pandas OHLCV table, dated annotations and indicator values into chart layers. The same snapshot supplies a Markdown report or a notebook view.
FromDataFrame
Take a copy of the OHLCV rows and return a ChartSpec. Times must increase and be unique. For local times without an offset, provide assume_timezone. Custom markers and lines match candle timestamps exactly, including when only selected bars are annotated. Supply computed series to add indicators.
FromDataFrame(
prices,
*,
assume_timezone: str | None = None,
title: str = 'PriceGenerator',
markers=None,
lines=(),
series=(),
summary=(),
theme: str = 'dark',
width: int = 1280,
height: int = 760,
price_precision: int = 2,
show_controls: bool = True,
) -> ChartSpec
Parameters (12)
prices- Nonempty OHLCV DataFrame with unique column names and strictly increasing, unique candle times. The expected columns are datetime, open, high, low, close and volume.
assume_timezone- Time zone for timestamps that have no offset, for example Europe/London. Times with offsets are converted to UTC. Ambiguous or nonexistent local times are rejected.
title- Title displayed on the chart and used as the heading of a separately exported Markdown report.
markers- Optional DataFrame with datetime and at least one of markersUpper, markersCenter or markersLower for text above, inside or below candles. Each timestamp must match one candle. Empty text is skipped.
lines- Sequence of DataFrames with a datetime column and one or more named numeric columns. Each numeric column becomes a layer. Missing candle timestamps leave gaps in that layer.
series- ChartSeries overlays. Each series has a unique key and supplies exactly one value or None per candle.
summary- Sequence of report text lines. HTML places the details behind an expandable section. Static exports place the text below the plot.
theme- Initial palette, dark or light. The default is dark. Readers can switch it on an interactive chart.
width- Chart width in pixels, an integer from 480 to 16384 inclusive.
height- Chart height in pixels, from 360 to 16384 inclusive. A static export can be taller when the legend or summary needs extra space.
price_precision- Number of decimal places for ordinary displayed prices, from 0 to 12. This is a label setting. The underlying candle values retain their precision.
show_controls- Whether to display the interactive chart’s control bar, including zoom, theme and image export actions.
IndicatorOverlays
Convert an IndicatorReport to a tuple of ChartSeries, preserving bar alignment, gaps, plotting style and group names. All returned layers start hidden. Use the HTML indicator controls to show a group.
IndicatorOverlays(report) -> tuple[ChartSeries, ...]
Parameters (1)
report- IndicatorReport produced by Indicators, containing computed, bar-aligned indicator series.
MarketOverlays
Return chart layers for close extrema, the line between the first and last close, each bar’s high/low midpoint, and technical indicators. Optionally add endpoint lines for consecutive segments. The extrema and endpoint lines depend on the complete period. ZigZag connects confirmed turning points retrospectively using elapsed UTC time.
MarketOverlays(
frame,
*,
split_counts=(),
zigzag_deviation: float = 0.05,
) -> tuple[ChartSeries, ...]
Parameters (3)
frame- OHLCV DataFrame with datetime, open, high, low, close and volume columns. Rows must be ordered in time and pass the package’s market-data checks.
split_counts- Lengths of consecutive candle segments. Every length must be a positive integer and the total must equal the candle count. Leave empty to omit segment endpoint lines.
zigzag_deviation- Relative reversal threshold for the ZigZag series, strictly between 0 and 1. The default 0.05 requires a 5% move from the extreme.
RenderMarkdown
Return a Markdown string containing the chart title and the summary lines already in the specification. Embedded HTML characters are escaped. Add analysis when preparing the chart if you want its statistical report here.
RenderMarkdown(spec: ChartSpec) -> str
Parameters (1)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
SaveMarkdown
Write the title and existing summary to a UTF-8 Markdown file and return its Path. Use a separate path from the chart file when saving both.
SaveMarkdown(spec: ChartSpec, path: str | Path) -> Path
Parameters (2)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
path- Destination filename or pathlib.Path. Its parent directory must exist. The save operation replaces an existing file at this path.
NotebookHTML
Return HTML for an isolated iframe containing the interactive chart. This lets several offline charts coexist in one notebook. To show it immediately, call DisplayChart.
NotebookHTML(spec: ChartSpec) -> str
Parameters (1)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
DisplayChart
Display a prepared ChartSpec through IPython. Choose interactive HTML or inline SVG. Requires pricegenerator[notebook] and returns the result of the IPython display call, typically a display handle in Jupyter.
DisplayChart(spec: ChartSpec, *, format: str = 'html') -> Any
Parameters (2)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
format- Notebook output type. Use html for an interactive view or svg for a static vector graphic.
pricegenerator.rendering.interactive
Build a self-contained HTML chart for exploring individual candles and trading volume, switching indicator groups, and exporting the current view from the browser.
RenderInteractive
Return a complete offline HTML document with candle and volume panels. Readers can inspect bars, zoom, switch theme and toggle supplied overlay groups. The browser’s Export PNG control saves the current price and volume view, including selected layers, without the range slider or report.
RenderInteractive(spec: ChartSpec) -> str
Parameters (1)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
SaveInteractive
Write a self-contained HTML chart to a UTF-8 file and return its Path. Open the saved file in a browser to explore it. Data and chart scripts are included in the file.
SaveInteractive(spec: ChartSpec, path: str | Path) -> Path
Parameters (2)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
path- Destination filename or pathlib.Path. Its parent directory must exist. The save operation replaces an existing file at this path.
pricegenerator.rendering.static
Draw a portable SVG with candles, volume, visible overlays and annotations. The renderer works without a browser and lays out any accompanying report below the chart.
RenderSVG
Return SVG text showing candle bodies from open to close, wicks from low to high, and a separate volume panel. Rising candles have hollow bodies and falling candles are filled. Visible overlays, annotations and any supplied summary are included. No optional raster dependencies are needed.
RenderSVG(spec: ChartSpec) -> str
Parameters (1)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
SaveSVG
Write the complete vector chart as UTF-8 SVG and return its Path. The file can be viewed offline or embedded in documentation.
SaveSVG(spec: ChartSpec, path: str | Path) -> Path
Parameters (2)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
path- Destination filename or pathlib.Path. Its parent directory must exist. The save operation replaces an existing file at this path.
pricegenerator.rendering.exports
Export a static chart as PNG or JPEG with the optional pricegenerator[export] dependencies. The saved image uses the SVG layout, including any visible overlays and report text supplied in the specification.
RenderPNG
Return PNG image bytes using the static SVG layout. The image contains candles, volume and any visible layers. A supplied summary appears below the plot. Requires pricegenerator[export].
RenderPNG(spec: ChartSpec) -> bytes
Parameters (1)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
SavePNG
Write the static PNG image to the chosen path and return a Path. Use it to save a reproducible view of the visible series without opening a browser.
SavePNG(spec: ChartSpec, path: str | Path) -> Path
Parameters (2)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
path- Destination filename or pathlib.Path. Its parent directory must exist. The save operation replaces an existing file at this path.
RenderJPEG
Return RGB JPEG image bytes from the same static view as PNG. Transparent pixels are composited onto the selected theme’s background. Quality is an integer from 1 to 95. Requires pricegenerator[export].
RenderJPEG(spec: ChartSpec, *, quality: int = 90) -> bytes
Parameters (2)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
quality- JPEG encoding quality from 1 to 95 inclusive, as an integer. The default is 90.
SaveJPEG
Write the static JPEG at the requested quality and return its Path. This uses the raster export dependencies and does not launch a browser.
SaveJPEG(spec: ChartSpec, path: str | Path, *, quality: int = 90) -> Path
Parameters (3)
spec- A validated ChartSpec containing the candles, annotations, overlays and display settings for this chart.
path- Destination filename or pathlib.Path. Its parent directory must exist. The save operation replaces an existing file at this path.
quality- JPEG encoding quality from 1 to 95 inclusive, as an integer. The default is 90.
pricegenerator.rendering.theme
Access the dark and light chart palettes and the packaged Fuzzy Technologies artwork used in chart files.
BrandingData
Return a fresh dictionary with wordmark and emblem keys. Each value is a PNG data URI suitable for embedding directly in an offline chart or document.
BrandingData() -> dict[str, str]
Module constants
THEMES- Read-only palettes named dark and light. Each maps roles such as up, down, grid and background to hexadecimal colors.