Go to file
2017-02-26 01:03:53 -08:00
_examples removing exception dep, saving blank canvas on checkRanges err 2017-02-22 17:15:13 -08:00
_images can rotate text + add y axis names 2016-08-06 21:59:46 -07:00
drawing can rotate text + add y axis names 2016-08-06 21:59:46 -07:00
.gitignore adding ignores. 2016-10-23 12:10:06 -07:00
.travis.yml travis. 2016-07-28 14:32:23 -07:00
annotation_series_test.go these tests are not a joke 2017-02-22 17:48:32 -08:00
annotation_series.go adding validation. 2017-02-03 11:26:53 -08:00
axis.go can just supply inverted ranges. 2017-01-09 17:57:45 -08:00
bar_chart_test.go handle zero values 2017-01-13 14:37:08 -08:00
bar_chart.go handle zero values 2017-01-13 14:37:08 -08:00
bollinger_band_series_test.go big api overhauls. 2016-07-29 18:24:25 -07:00
bollinger_band_series.go adding validation. 2017-02-03 11:26:53 -08:00
box_test.go text rotation works, ish. 2016-10-21 12:44:37 -07:00
box.go text rotation works, ish. 2016-10-21 12:44:37 -07:00
chart_test.go chart test. 2017-02-03 11:27:58 -08:00
chart.go defaults are hard. 2017-02-22 17:47:08 -08:00
concat_series_test.go big api overhauls. 2016-07-29 18:24:25 -07:00
concat_series.go adding validation. 2017-02-03 11:26:53 -08:00
continuous_range_test.go big api overhauls. 2016-07-29 18:24:25 -07:00
continuous_range.go descending 2017-01-10 13:50:17 -08:00
continuous_series_test.go adding validation. 2017-02-03 11:26:53 -08:00
continuous_series.go adding validation. 2017-02-03 11:26:53 -08:00
date_posix.go fixing windows handling of eastern standard time 2017-02-12 09:02:14 -08:00
date_test.go deferring creating market open times. 2017-02-12 09:10:21 -08:00
date_windows.go fixing windows est abbr 2017-02-12 14:09:00 -08:00
date.go deferring creating market open times. 2017-02-12 09:10:21 -08:00
defaults.go defaults are hard. 2017-02-22 17:47:08 -08:00
draw.go render box labels directly to renderer 2017-01-10 14:25:06 +00:00
ema_series_test.go big api overhauls. 2016-07-29 18:24:25 -07:00
ema_series.go adding validation. 2017-02-03 11:26:53 -08:00
file_util.go removing exception dep, saving blank canvas on checkRanges err 2017-02-22 17:15:13 -08:00
grid_line_test.go fixing build. 2016-08-11 22:24:40 -07:00
grid_line.go changing gridline behavior. 2016-08-11 20:42:25 -07:00
histogram_series_test.go big api overhauls. 2016-07-29 18:24:25 -07:00
histogram_series.go adding validation. 2017-02-03 11:26:53 -08:00
image_writer.go adding validation. 2017-02-03 11:26:53 -08:00
last_value_annotation_series.go last annotation helper 2016-08-06 15:53:14 -07:00
legend_test.go hit coverage min, but not quite done yet. 2016-08-06 00:26:17 -07:00
legend.go slight tweak to legend (adds a new style) and example 2017-02-13 00:27:02 -08:00
LICENSE license and readme. 2016-07-07 20:37:57 -07:00
linear_regression_series_test.go big api overhauls. 2016-07-29 18:24:25 -07:00
linear_regression_series.go adding validation. 2017-02-03 11:26:53 -08:00
macd_series_test.go fixing macd inversion. 2016-07-18 17:41:59 -07:00
macd_series.go adding validation. 2017-02-03 11:26:53 -08:00
Makefile testing histogram series. 2016-07-28 16:36:30 -07:00
market_hours_range_test.go deferring creating market open times. 2017-02-12 09:10:21 -08:00
market_hours_range.go deferring creating market open times. 2017-02-12 09:10:21 -08:00
math_util_test.go finalizing work on text rotation. 2016-10-20 15:21:52 -07:00
math_util.go max 2017-02-26 01:03:47 -08:00
min_max_series.go adding validation. 2017-02-03 11:26:53 -08:00
pie_chart_test.go handle zero values with error. 2017-01-13 14:07:42 -08:00
pie_chart.go adding validation. 2017-02-03 11:26:53 -08:00
range.go descending 2017-01-10 13:50:17 -08:00
raster_renderer.go Merge pull request #13 from wcharczuk/text-rotation 2016-10-21 12:53:01 -07:00
README.md readme updates. 2016-08-07 11:05:57 -07:00
renderable.go api tweaks. 2016-07-14 18:29:06 -07:00
renderer_provider.go snapshot. 2016-07-10 01:11:47 -07:00
renderer.go text rotation works, ish. 2016-10-21 12:44:37 -07:00
ring_buffer_test.go moving averages! dashes! 2016-07-14 09:27:23 -07:00
ring_buffer.go tests. 2016-07-27 12:34:15 -07:00
roboto.go initial commit. 2016-07-06 18:54:00 -07:00
sequence_test.go deferring creating market open times. 2017-02-12 09:10:21 -08:00
sequence.go bar charts! 2016-08-05 16:55:55 -07:00
series.go adding validation. 2017-02-03 11:26:53 -08:00
sma_series_test.go big api overhauls. 2016-07-29 18:24:25 -07:00
sma_series.go adding validation. 2017-02-03 11:26:53 -08:00
stacked_bar_chart.go adding validation. 2017-02-03 11:26:53 -08:00
style_test.go text options! 2016-07-29 16:36:29 -07:00
style.go snapshot. 2016-09-05 13:26:12 -07:00
text_test.go big api overhauls. 2016-07-29 18:24:25 -07:00
text.go tweaks to make ticks not be terrible 2016-07-31 16:54:09 -07:00
tick_test.go descending 2017-01-10 13:50:17 -08:00
tick.go descending 2017-01-10 13:50:17 -08:00
time_series_test.go adding validation. 2017-02-03 11:26:53 -08:00
time_series.go adding validation. 2017-02-03 11:26:53 -08:00
time_util.go finalizing work on text rotation. 2016-10-20 15:21:52 -07:00
value_formatter_provider.go mostly works. 2016-07-10 10:43:04 -07:00
value_formatter_test.go finalizing work on text rotation. 2016-10-20 15:21:52 -07:00
value_formatter.go coverage goal is 70% by the end of the night. 2016-08-05 20:44:40 -07:00
value_provider.go bad interface format 2016-07-18 15:44:22 -07:00
value_test.go test updates. 2016-07-28 18:56:45 -07:00
value.go handle zero values with error. 2017-01-13 14:07:42 -08:00
vector_renderer_test.go text options! 2016-07-29 16:36:29 -07:00
vector_renderer.go text rotation works, ish. 2016-10-21 12:44:37 -07:00
xaxis_test.go fixing tests. 2016-07-30 20:20:59 -07:00
xaxis.go can just supply inverted ranges. 2017-01-09 17:57:45 -08:00
yaxis_test.go fixing tests. 2016-07-30 20:20:59 -07:00
yaxis.go can just supply inverted ranges. 2017-01-09 17:57:45 -08:00

go-chart

Build StatusGo Report Card

Package chart is a very simple golang native charting library that supports timeseries and continuous line charts.

The v1.0 release has been tagged so things should be more or less stable, if something changes please log an issue.

Master should now be on the v2.x codebase, which brings a couple new features and better handling of basics like axes labeling etc. 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 web servers, so start them with go run main.go then access http://localhost:8080 to see the output.

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. One complication here is any object's root chart.Style object (i.e named Style) and the Show property specifically, if any other property is set and the Show property is unset, it is assumed to be it's default value of False.

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

This library is super early but contributions are welcome.