.circleci | ||
_images | ||
cmd/chart | ||
drawing | ||
examples | ||
matrix | ||
roboto | ||
.gitignore | ||
annotation_series.go | ||
annotation_series_test.go | ||
array.go | ||
axis.go | ||
bar_chart.go | ||
bar_chart_test.go | ||
bollinger_band_series.go | ||
bollinger_band_series_test.go | ||
bounded_last_values_annotation_series.go | ||
box.go | ||
box_test.go | ||
chart.go | ||
chart_test.go | ||
colors.go | ||
concat_series.go | ||
concat_series_test.go | ||
continuous_range.go | ||
continuous_range_test.go | ||
continuous_series.go | ||
continuous_series_test.go | ||
COVERAGE | ||
defaults.go | ||
donut_chart.go | ||
donut_chart_test.go | ||
draw.go | ||
ema_series.go | ||
ema_series_test.go | ||
fileutil.go | ||
first_value_annotation.go | ||
first_value_annotation_test.go | ||
font.go | ||
grid_line.go | ||
grid_line_test.go | ||
histogram_series.go | ||
histogram_series_test.go | ||
image_writer.go | ||
jet.go | ||
last_value_annotation_series.go | ||
last_value_annotation_series_test.go | ||
legend.go | ||
legend_test.go | ||
LICENSE | ||
linear_coefficient_provider.go | ||
linear_regression_series.go | ||
linear_regression_series_test.go | ||
linear_sequence.go | ||
linear_series.go | ||
logger.go | ||
macd_series.go | ||
macd_series_test.go | ||
Makefile | ||
mathutil.go | ||
min_max_series.go | ||
parse.go | ||
percent_change_series.go | ||
percent_change_series_test.go | ||
pie_chart.go | ||
pie_chart_test.go | ||
polynomial_regression_series.go | ||
polynomial_regression_test.go | ||
PROFANITY_RULES.yml | ||
random_sequence.go | ||
range.go | ||
raster_renderer.go | ||
README.md | ||
renderable.go | ||
renderer.go | ||
renderer_provider.go | ||
seq.go | ||
seq_test.go | ||
series.go | ||
sma_series.go | ||
sma_series_test.go | ||
stacked_bar_chart.go | ||
stringutil.go | ||
stringutil_test.go | ||
style.go | ||
style_test.go | ||
text.go | ||
text_test.go | ||
tick.go | ||
tick_test.go | ||
time_series.go | ||
time_series_test.go | ||
times.go | ||
timeutil.go | ||
value.go | ||
value_buffer.go | ||
value_buffer_test.go | ||
value_formatter.go | ||
value_formatter_provider.go | ||
value_formatter_test.go | ||
value_provider.go | ||
value_test.go | ||
vector_renderer.go | ||
vector_renderer_test.go | ||
viridis.go | ||
xaxis.go | ||
xaxis_test.go | ||
yaxis.go | ||
yaxis_test.go |
go-chart
Package chart
is a very simple golang native charting library that supports timeseries and continuous line charts.
Master should now be on the v3.x codebase, which overhauls the api significantly. Per usual, see examples
for more information.
Installation
To install chart
run the following:
> go get -u github.com/wcharczuk/go-chart
Most of the components are interchangeable so feel free to crib whatever you want.
Output Examples
Spark Lines:
Single axis:
Two axis:
Other Chart Types
Pie Chart:
The code for this chart can be found in examples/pie_chart/main.go
.
Stacked Bar:
The code for this chart can be found in examples/stacked_bar/main.go
.
Code Examples
Actual chart configurations and examples can be found in the ./examples/
directory. They are simple CLI programs that write to output.png
(they are also updated with go generate
.
Usage
Everything starts with the chart.Chart
object. The bare minimum to draw a chart would be the following:
import (
...
"bytes"
...
"github.com/wcharczuk/go-chart" //exposes "chart"
)
graph := chart.Chart{
Series: []chart.Series{
chart.ContinuousSeries{
XValues: []float64{1.0, 2.0, 3.0, 4.0},
YValues: []float64{1.0, 2.0, 3.0, 4.0},
},
},
}
buffer := bytes.NewBuffer([]byte{})
err := graph.Render(chart.PNG, buffer)
Explanation of the above: A chart
can have many Series
, a Series
is a collection of things that need to be drawn according to the X range and the Y range(s).
Here, we have a single series with x range values as float64s, rendered to a PNG. Note; we can pass any type of io.Writer
into Render(...)
, meaning that we can render the chart to a file or a resonse or anything else that implements io.Writer
.
API Overview
Everything on the chart.Chart
object has defaults that can be overriden. Whenever a developer sets a property on the chart object, it is to be assumed that value will be used instead of the default.
The best way to see the api in action is to look at the examples in the ./_examples/
directory.
Design Philosophy
I wanted to make a charting library that used only native golang, that could be stood up on a server (i.e. it had built in fonts).
The goal with the API itself is to have the "zero value be useful", and to require the user to not code more than they absolutely needed.
Contributions
Contributions are welcome though this library is in a holding pattern for the forseable future.