Skip to content
dethrandirPublic

About

String charts for financials with C

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

ccharts

Version License: MIT PyPI version crates.io npm NuGet Maven Central RubyGems LuaRocks

BuyMeACoffee

Financial and statistical data in, a string out. High-density terminal charts drawn with Unicode block characters and returned as plain text strings — so the chart goes wherever text goes: a terminal, a log line, a chat message, an HTML <pre>, a commit comment, or a printf.

  328.00████████████                                                
                   █                                                
                   █           █████████████▁▁▁▁▁▁▁▁▁▁▁▁            
                   █████████████                       █            
                                                       █            
                                                       █            
                                                       █            
  301.00                                               █▁▁▁▁▁▁▁▁▁▁▁▁
2026-07-20                                                2026-07-24

There is no canvas, no image buffer, no GUI, and no terminal detection hooks — one function call returns a string, and what you do with it is your business.

Written as a single-header C89 library with a flat C ABI and idiomatic bindings for Python, Rust, Go, JavaScript/WASM, .NET/C#, Java, Ruby, Lua, Julia, and iyi. All bindings target the same byte-for-byte conformance corpus; see each binding’s validation notes for tested platforms.


Language Ecosystem

Language Package / Target Registry Installation Command
Python ccharts PyPI pip install ccharts (or pip install ccharts[pandas])
Rust ccharts crates.io cargo add ccharts
Go ccharts GitHub go get github.com/dethrandir/ccharts/bindings/go/ccharts
JavaScript / WASM @dethrandir/ccharts npm npm install @dethrandir/ccharts
.NET / C# Ccharts NuGet dotnet add package Ccharts
Java (JDK 22+) io.github.dethrandir:ccharts Maven Central Maven / Gradle dependency
Ruby ccharts RubyGems gem install ccharts
Lua ccharts LuaRocks luarocks install ccharts
Julia Ccharts General using Pkg; Pkg.add("Ccharts")
iyi github.com/dethrandir/ccharts/v3 Git iyi get github.com/dethrandir/ccharts/v3@main + native build

iyi binding

The iyi binding supports all nine chart types through the same C ABI, with typed errors and a small JSON-to-chart CLI. Run python3 bindings/iyi/scripts/dev.py test from this checkout. It requires iyi 0.20.1 and an explicit native build. Install from @main; existing release tags predate this addition.

python3 bindings/iyi/scripts/dev.py cli
fl market history THYAO 1m 1d --json | bindings/iyi/build/ccharts-market

Supported Chart Types

ccharts supports 9 visual chart types, each optimized with fractional Unicode glyphs:

  1. Line Chart          2. Candlestick          3. Pie / Donut
  328.00██████             330.25▄▄▄▄▄ █████               ████████      
              █                         │                ████████████    
              █                                         ██████  ██████   
              █▁▁▁▁                     █████           ████      ████   
                                300.75  █████             ██████████     
                                2026-07-20              Kira  40 (40%)

  4. Histogram           5. Sparkline            6. Categorical Bar
         8     ████      ▂▃▅▆▇██▇▆▅▄▃            100.00      ████        
               ████                                          ████  ████  
         1 ████████                              0.00  ████  ████  ████  
       3.10    7.90                                    Q1    Q2    Q3    

  7. Stacked Bar         8. Heatmap              9. Box Plot
       150.00  ████      Mon █ █ █ █ █ █         120.00        │         
               ████      Tue █ █ █ █ █ █                       ████      
         0.00  ████      Wed █ █ █ █ █ █          10.00  ▂     █   │     
               Prod      Thu █ █ █ █ █ █                 Cat A Cat B     
  1. Line (line): High-resolution curves using 8 vertical sub-pixel levels (▁▂▃▄▅▆▇█). Supports area fills, single or directional colors, and automatic downsampling.
  2. Candlestick (candle): Open, High, Low, Close (OHLC) financial charts with solid bodies (▀▄█), thin vertical wicks (│), and automatic downsampling (cc_agg_ohlc).
  3. Pie & Donut (pie): Proportional charts with terminal aspect ratio compensation, custom hole sizes (donut=True), slice gaps, center text, and customizable legends.
  4. Histogram (histogram / hist): Frequency distributions across continuous sample data with automatic or custom binning and outlier clamping.
  5. Sparkline (sparkline / spark): Compact, axis-less micro trend lines (height 1 to 3) for inline dashboards and log lines.
  6. Bar (bar): Categorical bar charts scaled from a shared zero baseline with 8 sub-pixel tops and categorical label footers.
  7. Stacked Bar (stacked_bar / stack): Multi-series part-to-whole categorical breakdowns showing total sums and series segments.
  8. Heatmap (heatmap / heat): 2-D matrix density visualization using a 10-step deterministic colormap ladder and 2-D block-average downsampling.
  9. Box Plot (boxplot / box): Statistical 5-number summaries ($Min, Q_1, Median, Q_3, Max$) computed deterministically via nearest-rank quartiles.

Quickstart Examples

C (Single-Header)

#define CCHARTS_IMPLEMENTATION
#include "ccharts.h"

int main(void) {
    const char* json = "[{\"open\":100,\"high\":105,\"low\":98,\"close\":103}]";
    cc_ohlc_t* ohlc = NULL;
    int size = 0;
    cc_json_to_ohlc(json, &ohlc, &size);

    cc_settings_t s = { .rise_color = CC_COLOR_BLUE, .show_prices = 1, .show_times = 1 };
    char* chart = cc_line_create(ohlc, size, 60, 8, &s);
    printf("%s\n", chart);

    free(chart);
    free(ohlc);
    return 0;
}

Python

from ccharts import Chart

# OHLC Chart
chart = Chart.from_arrays(opens, highs, lows, closes, ts=epoch_seconds)
print(chart.candle(width=60, height=8, show_prices=True))

# Standalone Visuals
print(Chart.pie(["Rent", "Food", "Tech"], [45, 30, 25], donut=True))
print(Chart.histogram(samples, bin_count=10, show_bins=True))
print(Chart.sparkline(samples, height=1))

Rust

use ccharts::{Chart, Color, Settings, PieSlice, PieOptions};

let chart = Chart::from_arrays(&opens, &highs, &lows, &closes, Some(&ts))?;
println!("{}", chart.line(60, 8, &Settings::new().rise(Color::Blue))?);

let slices = [PieSlice::new(Some("Rent"), 45.0), PieSlice::new(Some("Food"), 30.0)];
println!("{}", Chart::pie(&slices, 24, 10, &PieOptions::new().donut(true))?);

Go

chart, _ := ccharts.FromArrays(opens, highs, lows, closes, ts)
defer chart.Close()
out, _ := chart.Candle(60, 8, &ccharts.Options{ShowPrices: true})
fmt.Println(out)

JavaScript / WASM

import { Chart, Color } from "@dethrandir/ccharts";

const chart = Chart.fromArrays(opens, highs, lows, closes);
console.log(chart.candle({ width: 60, height: 8, showPrices: true }));
chart.free();

.NET / C#

using var chart = Chart.FromArrays(opens, highs, lows, closes);
Console.Write(chart.Line(new ChartOptions { RiseColor = Color.Blue, ShowPrices = true }));

Java (JDK 22+)

try (Chart chart = Chart.fromArrays(opens, highs, lows, closes)) {
    System.out.print(chart.candle(ChartOptions.builder().size(60, 8).showPrices(true).build()));
}

Ruby

chart = Ccharts::Chart.from_arrays(open: opens, high: highs, low: lows, close: closes)
puts chart.line(60, 8, Ccharts::Settings::ChartSettings.new.show_prices(true))

Lua

local chart = ccharts.from_arrays(opens, highs, lows, closes)
print(chart:candle(60, 8, { show_prices = true }))

Julia

chart = Chart.from_arrays(opens, highs, lows, closes)
println(chart.candle(60, 8; show_prices=true))

Settings & Colors

Field Meaning Default
rise_color Color for rising segments / bars / boxes Green (\x1b[32m)
fall_color Color for falling segments / candles Red (\x1b[31m)
bg_color Background of empty cells None (terminal default)
area_color Line fill color / Whiskers color None
single_color 1 = one uniform line color; 0 = per-segment direction 0
show_prices Prepend 8-column price/count value axis 0
show_times Append first/last timestamp footer 0
plain Strip all ANSI escape sequences 0

Setting plain=True (or passing empty strings for color options) completely strips ANSI escape codes, rendering clean plain text ideal for file exports, commit comments, Discord code blocks, and logs.


Detailed Documentation

Comprehensive guides are available in the docs/ directory:

  • 🚀 Getting Started — Installation, building from source, and basic usage across all languages.
  • 📊 Chart Types Guide — In-depth parameters, sub-pixel rendering mechanics, and visual outputs for all 9 chart types.
  • 🔌 Language Bindings Guide — Package managers, memory management (RAII/Cleaners/Finalizers), and cross-language API mappings.
  • 🛠️ C API & Flat ABI Reference — Single-header macros, structs, functions, and ABI status code contracts.
  • 🏗️ Architecture & Engine Design — Sub-pixel grid pipeline, downsampling math, 32-byte slot memory model, and determinism.

Repository Structure

  • ccharts.h — Core single-header C library containing all rendering algorithms.
  • abi/ — Flat C ABI (ccharts_abi.h/.c) exporting opaque handles and error codes for FFIs.
  • bindings/ — Idiomatic bindings:
    • bindings/rust/ — Rust crate (ccharts).
    • bindings/go/ — Go module (ccharts).
    • bindings/js/ — Standalone WebAssembly npm package (@dethrandir/ccharts).
    • bindings/dotnet/ — .NET 8+ P/Invoke package (Ccharts).
    • bindings/java/ — Java 22+ FFM API library (io.github.dethrandir:ccharts).
    • bindings/ruby/ — Ruby gem (ccharts).
    • bindings/lua/ — LuaRocks package (ccharts).
    • bindings/julia/ — Julia package (Ccharts).
    • bindings/iyi/ — iyi FFI binding, native build helper, tests and financial JSON CLI.
  • iyi.mod / ccharts.iyi — iyi package identity and public entry point.
  • ccharts/ — Python package (ccharts) wrapping C core + pandas integration.
  • docs/ — Modular documentation guides.
  • conformance/ — 70 cross-language test cases (cases.json) and byte-for-byte golden files (golden/*.txt).
  • scripts/ — Version consistency checks, source sync tools, and golden generators.

License

ccharts is released under the MIT License.

About

String charts for financials with C

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages