百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

asciigraph

> DevOps
开源

用于在命令行应用中绘制轻量级ASCII折线图的Go包,无其他依赖。

3.1K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

用于在命令行应用中绘制轻量级ASCII折线图的Go包,无其他依赖。

asciigraph

[![构建状态][]][1] [![Go 报告卡][]][2] [![覆盖率状态][]][3] [![GoDoc][]][4] [![许可证][]][5] [![在 Awesome Go 中被提及][]][6]

用于制作轻量级 ASCII 折线图的 Go 包 ╭┈╯。

安装

bash
go get -u github.com/guptarohit/asciigraph@latest

用法

基本图表

go
package main

import (
    "fmt"
    "github.com/guptarohit/asciigraph"
)

func main() {
    data := []float64{3, 4, 9, 6, 2, 4, 5, 8, 5, 10, 2, 7, 2, 5, 6}
    graph := asciigraph.Plot(data)

    fmt.Println(graph)
}

运行此示例将渲染以下图表:

bash
  10.00 ┤        ╭╮
   9.00 ┤ ╭╮     ││
   8.00 ┤ ││   ╭╮││
   7.00 ┤ ││   ││││╭╮
   6.00 ┤ │╰╮  ││││││ ╭
   5.00 ┤ │ │ ╭╯╰╯│││╭╯
   4.00 ┤╭╯ │╭╯   ││││
   3.00 ┼╯  ││    ││││
   2.00 ┤   ╰╯    ╰╯╰╯

多系列

go
package main

import (
    "fmt"
    "github.com/guptarohit/asciigraph"
)

func main() {
	data := [][]float64{{0, 1, 2, 3, 3, 3, 2, 0}, {5, 4, 2, 1, 4, 6, 6}}
	graph := asciigraph.PlotMany(data)

	fmt.Println(graph)
}

运行此示例将渲染以下图表:

bash
 6.00 ┤    ╭─
 5.00 ┼╮   │
 4.00 ┤╰╮ ╭╯
 3.00 ┤ │╭│─╮
 2.00 ┤ ╰╮│ ╰╮
 1.00 ┤╭╯╰╯  │
 0.00 ┼╯     ╰

自定义 Y 轴值格式化

使用 YAxisValueFormatter(...) 来控制 Y 轴上打印的值的渲染方式。 这对于人类可读的单位(如字节、时长或特定领域的标签)非常有用。

go
package main

import (
	"fmt"

	"github.com/guptarohit/asciigraph"
)

func main() {
	data := []float64{
		30 * 1024 * 1024 * 1024,
		70 * 1024 * 1024 * 1024,
		2 * 1024 * 1024 * 1024,
	}

	graph := asciigraph.Plot(data,
		asciigraph.Height(5),
		asciigraph.Width(45),
		asciigraph.YAxisValueFormatter(func(v float64) string {
			return fmt.Sprintf("%.2f GiB", v/1024/1024/1024)
		}),
	)

	fmt.Println(graph)
}

运行此示例将渲染以下图形:

bash
 70.00 GiB ┤                 ╭──────╮
 56.40 GiB ┤         ╭───────╯      ╰────╮
 42.80 GiB ┤  ╭──────╯                   ╰───╮
 29.20 GiB ┼──╯                              ╰────╮
 15.60 GiB ┤                                      ╰───╮
  2.00 GiB ┤

![image][]

Issues· 5 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Goascii-chartasciigraphchartcharting-library

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理