go chart is a basic charting library in go.
Find a file
2016-07-10 17:19:59 -07:00
drawing with alpha. 2016-07-09 11:26:28 -07:00
images readme updates. 2016-07-10 11:30:51 -07:00
testserver fixing bug with annotations with axis turned off. 2016-07-10 16:26:18 -07:00
.travis.yml fixing bug with annotations with axis turned off. 2016-07-10 16:26:18 -07:00
annotation_series.go bugfixes with mixed ranges. 2016-07-10 17:19:44 -07:00
axis.go mostly works. 2016-07-10 10:43:04 -07:00
box.go snapshot. 2016-07-10 01:11:47 -07:00
chart.go bugfixes with mixed ranges. 2016-07-10 17:19:44 -07:00
chart_test.go fixing tests. 2016-07-10 11:27:12 -07:00
continuous_series.go mostly works. 2016-07-10 10:43:04 -07:00
defaults.go mostly works. 2016-07-10 10:43:04 -07:00
drawing_helpers.go fixing bug with annotations with axis turned off. 2016-07-10 16:26:18 -07:00
LICENSE license and readme. 2016-07-07 20:37:57 -07:00
point.go initial commit. 2016-07-06 18:54:00 -07:00
range.go snapshot. 2016-07-10 01:11:47 -07:00
range_test.go updates. 2016-07-07 14:44:03 -07:00
raster_renderer.go snapshot. 2016-07-10 01:11:47 -07:00
README.md Update README.md 2016-07-10 16:28:20 -07:00
renderable.go snapshot. 2016-07-10 01:11:47 -07:00
renderer.go mostly works. 2016-07-10 10:43:04 -07:00
renderer_provider.go snapshot. 2016-07-10 01:11:47 -07:00
roboto.go initial commit. 2016-07-06 18:54:00 -07:00
series.go snapshot. 2016-07-10 01:11:47 -07:00
style.go snapshot. 2016-07-10 01:11:47 -07:00
tick.go snapshot. 2016-07-10 01:11:47 -07:00
time_series.go mostly works. 2016-07-10 10:43:04 -07:00
time_series_test.go updates 2016-07-09 20:14:11 -07:00
util.go snapshot. 2016-07-10 01:11:47 -07:00
util_test.go things work more or less, added a testing service. 2016-07-07 17:14:25 -07:00
value_formatter.go mostly works. 2016-07-10 10:43:04 -07:00
value_formatter_provider.go mostly works. 2016-07-10 10:43:04 -07:00
value_provider.go snapshot. 2016-07-10 01:11:47 -07:00
vector_renderer.go snapshot. 2016-07-10 01:11:47 -07:00
xaxis.go bugfixes with mixed ranges. 2016-07-10 17:19:44 -07:00
yaxis.go bugfixes with mixed ranges. 2016-07-10 17:19:44 -07:00

go-chart

Build Status

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

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.

Usage

The chart code to produce the above is as follows:

// note this assumes that xvalues and yvalues
// have been pulled from a pricing service.
graph := chart.Chart{
    Width:  1024,
    Height: 400,
    YAxis: chart.YAxis {
        Style: chart.Style{
            Show: true,
        },
    },
    XAxis: chart.XAxis {
        Style: chart.Style{
            Show: true,
        },
    },
    Series: []chart.Series{
        chart.TimeSeries{
            XValues: xvalues,
            YValues: yvalues,
            Style: chart.Style {
                FillColor: chart.DefaultSeriesStrokeColors[0].WithAlpha(64),
            },
        },
        chart.AnnotationSeries{
            Name: "Last Value",
            Style: chart.Style{
                Show:        true,
                StrokeColor: chart.DefaultSeriesStrokeColors[0],
            },
            Annotations: []chart.Annotation{
                chart.Annotation{
                    X:     float64(xvalues[len(xvalues)-1].Unix()), //todo: helpers for this.
                    Y:     yvalues[len(yvalues)-1],
                    Label: chart.FloatValueFormatter(yvalues[len(yvalues)-1]),
                },
            },
        },
    },
}
graph.Render(chart.PNG, buffer) //thats it!

The key areas to note are that we have to explicitly turn on two features, the axes and add the last value label annotation series. When calling .Render(..) we add a parameter, chart.PNG that tells the renderer to use a raster renderer. Another option is to use chart.SVG which will use the vector renderer and create an svg representation of the chart.

Alternate Usage

You can alternately turn a bunch of features off and constrain the proportions to something like a spark line:

The code to produce the above would be:

// note this assumes that xvalues and yvalues
// have been pulled from a pricing service.
graph := chart.Chart{
    Width:  1024,
    Height: 100,
    Series: []chart.Series{
        chart.TimeSeries{
            XValues: xvalues,
            YValues: yvalues,
        },
    },
}
graph.Render(chart.PNG, buffer)

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.