switching to generators
2
COVERAGE
|
@ -1 +1 @@
|
||||||
70.89
|
29.02
|
5
Makefile
|
@ -7,6 +7,9 @@ new-install:
|
||||||
@go get -v -u github.com/blend/go-sdk/cmd/coverage
|
@go get -v -u github.com/blend/go-sdk/cmd/coverage
|
||||||
@go get -v -u github.com/blend/go-sdk/cmd/profanity
|
@go get -v -u github.com/blend/go-sdk/cmd/profanity
|
||||||
|
|
||||||
|
generate:
|
||||||
|
@go generate ./...
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@go test ./...
|
@go test ./...
|
||||||
|
|
||||||
|
@ -15,4 +18,4 @@ profanity:
|
||||||
@profanity
|
@profanity
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
@coverage
|
@coverage
|
||||||
|
|
12
README.md
|
@ -2,12 +2,9 @@ go-chart
|
||||||
========
|
========
|
||||||
[![CircleCI](https://circleci.com/gh/wcharczuk/go-chart.svg?style=svg)](https://circleci.com/gh/wcharczuk/go-chart) [![Go Report Card](https://goreportcard.com/badge/github.com/wcharczuk/go-chart)](https://goreportcard.com/report/github.com/wcharczuk/go-chart)
|
[![CircleCI](https://circleci.com/gh/wcharczuk/go-chart.svg?style=svg)](https://circleci.com/gh/wcharczuk/go-chart) [![Go Report Card](https://goreportcard.com/badge/github.com/wcharczuk/go-chart)](https://goreportcard.com/report/github.com/wcharczuk/go-chart)
|
||||||
|
|
||||||
Package `chart` is a very simple golang native charting library that supports timeseries and continuous
|
Package `chart` is a very simple golang native charting library that supports timeseries and continuous line charts.
|
||||||
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 v3.x codebase, which overhauls the api significantly. Per usual, see `_examples` for more information.
|
||||||
|
|
||||||
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
|
# Installation
|
||||||
|
|
||||||
|
@ -83,8 +80,7 @@ Here, we have a single series with x range values as float64s, rendered to a PNG
|
||||||
|
|
||||||
# API Overview
|
# 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
|
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.
|
||||||
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.
|
The best way to see the api in action is to look at the examples in the `./_examples/` directory.
|
||||||
|
|
||||||
|
@ -96,4 +92,4 @@ The goal with the API itself is to have the "zero value be useful", and to requi
|
||||||
|
|
||||||
# Contributions
|
# Contributions
|
||||||
|
|
||||||
This library is super early but contributions are welcome.
|
Contributions are welcome though this library is in a holding pattern for the forseable future.
|
||||||
|
|
Before Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 24 KiB |
|
@ -1,57 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
|
||||||
)
|
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
||||||
sbc := chart.BarChart{
|
|
||||||
Title: "Test Bar Chart",
|
|
||||||
TitleStyle: chart.StyleShow(),
|
|
||||||
Background: chart.Style{
|
|
||||||
Padding: chart.Box{
|
|
||||||
Top: 40,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Height: 512,
|
|
||||||
BarWidth: 60,
|
|
||||||
XAxis: chart.StyleShow(),
|
|
||||||
YAxis: chart.YAxis{
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
Bars: []chart.Value{
|
|
||||||
{Value: 5.25, Label: "Blue"},
|
|
||||||
{Value: 4.88, Label: "Green"},
|
|
||||||
{Value: 4.74, Label: "Gray"},
|
|
||||||
{Value: 3.22, Label: "Orange"},
|
|
||||||
{Value: 3, Label: "Test"},
|
|
||||||
{Value: 2.27, Label: "??"},
|
|
||||||
{Value: 1, Label: "!!"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
|
||||||
err := sbc.Render(chart.PNG, res)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error rendering chart: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func port() string {
|
|
||||||
if len(os.Getenv("PORT")) > 0 {
|
|
||||||
return os.Getenv("PORT")
|
|
||||||
}
|
|
||||||
return "8080"
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
listenPort := fmt.Sprintf(":%s", port())
|
|
||||||
fmt.Printf("Listening on %s\n", listenPort)
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
log.Fatal(http.ListenAndServe(listenPort, nil))
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
|
||||||
)
|
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
||||||
graph := chart.Chart{
|
|
||||||
Series: []chart.Series{
|
|
||||||
chart.ContinuousSeries{
|
|
||||||
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
|
||||||
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
|
||||||
graph.Render(chart.PNG, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawChartWide(res http.ResponseWriter, req *http.Request) {
|
|
||||||
graph := chart.Chart{
|
|
||||||
Width: 1920, //this overrides the default.
|
|
||||||
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},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
|
||||||
graph.Render(chart.PNG, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.HandleFunc("/wide", drawChartWide)
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
||||||
}
|
|
Before Width: | Height: | Size: 11 KiB |
|
@ -1,79 +0,0 @@
|
||||||
// Usage: http://localhost:8080?series=100&values=1000
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
|
||||||
)
|
|
||||||
|
|
||||||
func random(min, max float64) float64 {
|
|
||||||
return rand.Float64()*(max-min) + min
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawLargeChart(res http.ResponseWriter, r *http.Request) {
|
|
||||||
numSeriesInt64, err := strconv.ParseInt(r.FormValue("series"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
numSeriesInt64 = int64(1)
|
|
||||||
}
|
|
||||||
if numSeriesInt64 == 0 {
|
|
||||||
numSeriesInt64 = 1
|
|
||||||
}
|
|
||||||
numSeries := int(numSeriesInt64)
|
|
||||||
|
|
||||||
numValuesInt64, err := strconv.ParseInt(r.FormValue("values"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
numValuesInt64 = int64(100)
|
|
||||||
}
|
|
||||||
if numValuesInt64 == 0 {
|
|
||||||
numValuesInt64 = int64(100)
|
|
||||||
}
|
|
||||||
numValues := int(numValuesInt64)
|
|
||||||
|
|
||||||
series := make([]chart.Series, numSeries)
|
|
||||||
|
|
||||||
for i := 0; i < numSeries; i++ {
|
|
||||||
xValues := make([]time.Time, numValues)
|
|
||||||
yValues := make([]float64, numValues)
|
|
||||||
|
|
||||||
for j := 0; j < numValues; j++ {
|
|
||||||
xValues[j] = time.Now().AddDate(0, 0, (numValues-j)*-1)
|
|
||||||
yValues[j] = random(float64(-500), float64(500))
|
|
||||||
}
|
|
||||||
|
|
||||||
series[i] = chart.TimeSeries{
|
|
||||||
Name: fmt.Sprintf("aaa.bbb.hostname-%v.ccc.ddd.eee.fff.ggg.hhh.iii.jjj.kkk.lll.mmm.nnn.value", i),
|
|
||||||
XValues: xValues,
|
|
||||||
YValues: yValues,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
graph := chart.Chart{
|
|
||||||
XAxis: chart.XAxis{
|
|
||||||
Name: "Time",
|
|
||||||
NameStyle: chart.StyleShow(),
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
YAxis: chart.YAxis{
|
|
||||||
Name: "Value",
|
|
||||||
NameStyle: chart.StyleShow(),
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
Series: series,
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
|
||||||
graph.Render(chart.PNG, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawLargeChart)
|
|
||||||
http.HandleFunc("/favico.ico", func(res http.ResponseWriter, req *http.Request) {
|
|
||||||
res.Write([]byte{})
|
|
||||||
})
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
|
Before Width: | Height: | Size: 68 KiB |
Before Width: | Height: | Size: 27 KiB |
|
@ -1,67 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
|
||||||
"github.com/wcharczuk/go-chart/seq"
|
|
||||||
)
|
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
||||||
graph := chart.Chart{
|
|
||||||
Background: chart.Style{
|
|
||||||
Padding: chart.Box{
|
|
||||||
Top: 50,
|
|
||||||
Left: 25,
|
|
||||||
Right: 25,
|
|
||||||
Bottom: 10,
|
|
||||||
},
|
|
||||||
FillColor: drawing.ColorFromHex("efefef"),
|
|
||||||
},
|
|
||||||
XAxis: chart.XAxis{
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
YAxis: chart.YAxis{
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
Series: []chart.Series{
|
|
||||||
chart.ContinuousSeries{
|
|
||||||
XValues: SeqRange(1.0, 100.0),
|
|
||||||
YValues: seq.RandomValuesWithMax(100, 512),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
|
||||||
graph.Render(chart.PNG, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawChartDefault(res http.ResponseWriter, req *http.Request) {
|
|
||||||
graph := chart.Chart{
|
|
||||||
Background: chart.Style{
|
|
||||||
FillColor: drawing.ColorFromHex("efefef"),
|
|
||||||
},
|
|
||||||
XAxis: chart.XAxis{
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
YAxis: chart.YAxis{
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
Series: []chart.Series{
|
|
||||||
chart.ContinuousSeries{
|
|
||||||
XValues: SeqRange(1.0, 100.0),
|
|
||||||
YValues: seq.RandomValuesWithMax(100, 512),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
|
||||||
graph.Render(chart.PNG, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.HandleFunc("/default", drawChartDefault)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
|
Before Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 19 KiB |
|
@ -1,54 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
|
||||||
)
|
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
||||||
pie := chart.DonutChart{
|
|
||||||
Width: 512,
|
|
||||||
Height: 512,
|
|
||||||
Values: []chart.Value{
|
|
||||||
{Value: 5, Label: "Blue"},
|
|
||||||
{Value: 5, Label: "Green"},
|
|
||||||
{Value: 4, Label: "Gray"},
|
|
||||||
{Value: 4, Label: "Orange"},
|
|
||||||
{Value: 3, Label: "Deep Blue"},
|
|
||||||
{Value: 3, Label: "test"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
|
||||||
err := pie.Render(chart.PNG, res)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error rendering pie chart: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawChartRegression(res http.ResponseWriter, req *http.Request) {
|
|
||||||
pie := chart.DonutChart{
|
|
||||||
Width: 512,
|
|
||||||
Height: 512,
|
|
||||||
Values: []chart.Value{
|
|
||||||
{Value: 5, Label: "Blue"},
|
|
||||||
{Value: 2, Label: "Two"},
|
|
||||||
{Value: 1, Label: "One"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Header().Set("Content-Type", chart.ContentTypeSVG)
|
|
||||||
err := pie.Render(chart.SVG, res)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error rendering pie chart: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.HandleFunc("/reg", drawChartRegression)
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
||||||
}
|
|
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 170 KiB |
|
@ -1,55 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
|
||||||
)
|
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
|
||||||
pie := chart.PieChart{
|
|
||||||
Width: 512,
|
|
||||||
Height: 512,
|
|
||||||
Values: []chart.Value{
|
|
||||||
{Value: 5, Label: "Blue"},
|
|
||||||
{Value: 5, Label: "Green"},
|
|
||||||
{Value: 4, Label: "Gray"},
|
|
||||||
{Value: 4, Label: "Orange"},
|
|
||||||
{Value: 3, Label: "Deep Blue"},
|
|
||||||
{Value: 3, Label: "??"},
|
|
||||||
{Value: 1, Label: "!!"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
|
||||||
err := pie.Render(chart.PNG, res)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error rendering pie chart: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawChartRegression(res http.ResponseWriter, req *http.Request) {
|
|
||||||
pie := chart.PieChart{
|
|
||||||
Width: 512,
|
|
||||||
Height: 512,
|
|
||||||
Values: []chart.Value{
|
|
||||||
{Value: 5, Label: "Blue"},
|
|
||||||
{Value: 2, Label: "Two"},
|
|
||||||
{Value: 1, Label: "One"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Header().Set("Content-Type", chart.ContentTypeSVG)
|
|
||||||
err := pie.Render(chart.SVG, res)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error rendering pie chart: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.HandleFunc("/reg", drawChartRegression)
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
||||||
}
|
|
Before Width: | Height: | Size: 54 KiB |
Before Width: | Height: | Size: 68 KiB |
Before Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 40 KiB |
|
@ -1,13 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
In this example we add an `Annotation` series, which is a special type of series that
|
In this example we add an `Annotation` series, which is a special type of series that
|
||||||
draws annotation labels at given X and Y values (as translated by their respective ranges).
|
draws annotation labels at given X and Y values (as translated by their respective ranges).
|
||||||
|
@ -37,11 +38,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/annotations/output.png
Normal file
After Width: | Height: | Size: 26 KiB |
|
@ -1,12 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The below will draw the same chart as the `basic` example, except with both the x and y axes turned on.
|
The below will draw the same chart as the `basic` example, except with both the x and y axes turned on.
|
||||||
|
@ -14,20 +16,9 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
XAxis: chart.XAxis{
|
|
||||||
Name: "The XAxis",
|
|
||||||
NameStyle: chart.StyleShow(),
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
YAxis: chart.YAxis{
|
|
||||||
Name: "The YAxis",
|
|
||||||
NameStyle: chart.StyleShow(),
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
chart.ContinuousSeries{
|
chart.ContinuousSeries{
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
|
||||||
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
|
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
|
||||||
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
|
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
|
||||||
},
|
},
|
||||||
|
@ -37,11 +28,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/axes/output.png
Normal file
After Width: | Height: | Size: 22 KiB |
|
@ -1,12 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The below will draw the same chart as the `basic` example, except with both the x and y axes turned on.
|
The below will draw the same chart as the `basic` example, except with both the x and y axes turned on.
|
||||||
|
@ -15,15 +17,14 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
XAxis: chart.XAxis{
|
XAxis: chart.XAxis{
|
||||||
Style: chart.StyleShow(), //enables / displays the x-axis
|
Name: "The XAxis",
|
||||||
},
|
},
|
||||||
YAxis: chart.YAxis{
|
YAxis: chart.YAxis{
|
||||||
Style: chart.StyleShow(), //enables / displays the y-axis
|
Name: "The YAxis",
|
||||||
},
|
},
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
chart.ContinuousSeries{
|
chart.ContinuousSeries{
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
|
||||||
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
|
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
|
||||||
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
|
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
|
||||||
},
|
},
|
||||||
|
@ -33,11 +34,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/axes_labels/output.png
Normal file
After Width: | Height: | Size: 24 KiB |
35
examples/bar_chart/main.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
graph := chart.BarChart{
|
||||||
|
Title: "Test Bar Chart",
|
||||||
|
Background: chart.Style{
|
||||||
|
Padding: chart.Box{
|
||||||
|
Top: 40,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Height: 512,
|
||||||
|
BarWidth: 60,
|
||||||
|
Bars: []chart.Value{
|
||||||
|
{Value: 5.25, Label: "Blue"},
|
||||||
|
{Value: 4.88, Label: "Green"},
|
||||||
|
{Value: 4.74, Label: "Gray"},
|
||||||
|
{Value: 3.22, Label: "Orange"},
|
||||||
|
{Value: 3, Label: "Test"},
|
||||||
|
{Value: 2.27, Label: "??"},
|
||||||
|
{Value: 1, Label: "!!"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
f, _ := os.Create("output.png")
|
||||||
|
defer f.Close()
|
||||||
|
graph.Render(chart.PNG, f)
|
||||||
|
}
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
|
@ -1,33 +1,29 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
profitStyle := chart.Style{
|
profitStyle := chart.Style{
|
||||||
Show: true,
|
|
||||||
FillColor: drawing.ColorFromHex("13c158"),
|
FillColor: drawing.ColorFromHex("13c158"),
|
||||||
StrokeColor: drawing.ColorFromHex("13c158"),
|
StrokeColor: drawing.ColorFromHex("13c158"),
|
||||||
StrokeWidth: 0,
|
StrokeWidth: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
lossStyle := chart.Style{
|
lossStyle := chart.Style{
|
||||||
Show: true,
|
|
||||||
FillColor: drawing.ColorFromHex("c11313"),
|
FillColor: drawing.ColorFromHex("c11313"),
|
||||||
StrokeColor: drawing.ColorFromHex("c11313"),
|
StrokeColor: drawing.ColorFromHex("c11313"),
|
||||||
StrokeWidth: 0,
|
StrokeWidth: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
sbc := chart.BarChart{
|
sbc := chart.BarChart{
|
||||||
Title: "Bar Chart Using BaseValue",
|
Title: "Bar Chart Using BaseValue",
|
||||||
TitleStyle: chart.StyleShow(),
|
|
||||||
Background: chart.Style{
|
Background: chart.Style{
|
||||||
Padding: chart.Box{
|
Padding: chart.Box{
|
||||||
Top: 40,
|
Top: 40,
|
||||||
|
@ -35,13 +31,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
Height: 512,
|
Height: 512,
|
||||||
BarWidth: 60,
|
BarWidth: 60,
|
||||||
XAxis: chart.Style{
|
|
||||||
Show: true,
|
|
||||||
},
|
|
||||||
YAxis: chart.YAxis{
|
YAxis: chart.YAxis{
|
||||||
Style: chart.Style{
|
|
||||||
Show: true,
|
|
||||||
},
|
|
||||||
Ticks: []chart.Tick{
|
Ticks: []chart.Tick{
|
||||||
{Value: -4.0, Label: "-4"},
|
{Value: -4.0, Label: "-4"},
|
||||||
{Value: -2.0, Label: "-2"},
|
{Value: -2.0, Label: "-2"},
|
||||||
|
@ -66,23 +56,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
err := sbc.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
if err != nil {
|
sbc.Render(chart.PNG, f)
|
||||||
fmt.Printf("Error rendering chart: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func port() string {
|
|
||||||
if len(os.Getenv("PORT")) > 0 {
|
|
||||||
return os.Getenv("PORT")
|
|
||||||
}
|
|
||||||
return "8080"
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
listenPort := fmt.Sprintf(":%s", port())
|
|
||||||
fmt.Printf("Listening on %s\n", listenPort)
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
log.Fatal(http.ListenAndServe(listenPort, nil))
|
|
||||||
}
|
}
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
23
examples/basic/main.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
graph := chart.Chart{
|
||||||
|
Series: []chart.Series{
|
||||||
|
chart.ContinuousSeries{
|
||||||
|
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
||||||
|
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
f, _ := os.Create("output.png")
|
||||||
|
defer f.Close()
|
||||||
|
graph.Render(chart.PNG, f)
|
||||||
|
}
|
BIN
examples/basic/output.png
Normal file
After Width: | Height: | Size: 24 KiB |
52
examples/benchmark_line_charts/main.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
|
)
|
||||||
|
|
||||||
|
func random(min, max float64) float64 {
|
||||||
|
return rand.Float64()*(max-min) + min
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
numValues := 1024
|
||||||
|
numSeries := 100
|
||||||
|
series := make([]chart.Series, numSeries)
|
||||||
|
|
||||||
|
for i := 0; i < numSeries; i++ {
|
||||||
|
xValues := make([]time.Time, numValues)
|
||||||
|
yValues := make([]float64, numValues)
|
||||||
|
|
||||||
|
for j := 0; j < numValues; j++ {
|
||||||
|
xValues[j] = time.Now().AddDate(0, 0, (numValues-j)*-1)
|
||||||
|
yValues[j] = random(float64(-500), float64(500))
|
||||||
|
}
|
||||||
|
|
||||||
|
series[i] = chart.TimeSeries{
|
||||||
|
Name: fmt.Sprintf("aaa.bbb.hostname-%v.ccc.ddd.eee.fff.ggg.hhh.iii.jjj.kkk.lll.mmm.nnn.value", i),
|
||||||
|
XValues: xValues,
|
||||||
|
YValues: yValues,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
graph := chart.Chart{
|
||||||
|
XAxis: chart.XAxis{
|
||||||
|
Name: "Time",
|
||||||
|
},
|
||||||
|
YAxis: chart.YAxis{
|
||||||
|
Name: "Value",
|
||||||
|
},
|
||||||
|
Series: series,
|
||||||
|
}
|
||||||
|
|
||||||
|
f, _ := os.Create("output.png")
|
||||||
|
defer f.Close()
|
||||||
|
graph.Render(chart.PNG, f)
|
||||||
|
}
|
BIN
examples/benchmark_line_charts/output.png
Normal file
After Width: | Height: | Size: 314 KiB |
|
@ -5,7 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Note: Additional examples on how to add Stylesheets are in the custom_stylesheets example
|
// Note: Additional examples on how to add Stylesheets are in the custom_stylesheets example
|
|
@ -1,13 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
/*
|
/*
|
||||||
In this example we use a custom `ValueFormatter` for the y axis, letting us specify how to format text of the y-axis ticks.
|
In this example we use a custom `ValueFormatter` for the y axis, letting us specify how to format text of the y-axis ticks.
|
||||||
You can also do this for the x-axis, or the secondary y-axis.
|
You can also do this for the x-axis, or the secondary y-axis.
|
||||||
|
@ -16,7 +18,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
YAxis: chart.YAxis{
|
YAxis: chart.YAxis{
|
||||||
Style: chart.StyleShow(),
|
|
||||||
ValueFormatter: func(v interface{}) string {
|
ValueFormatter: func(v interface{}) string {
|
||||||
if vf, isFloat := v.(float64); isFloat {
|
if vf, isFloat := v.(float64); isFloat {
|
||||||
return fmt.Sprintf("%0.6f", vf)
|
return fmt.Sprintf("%0.6f", vf)
|
||||||
|
@ -31,12 +32,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
f, _ := os.Create("output.png")
|
||||||
res.Header().Set("Content-Type", "image/png")
|
defer f.Close()
|
||||||
graph.Render(chart.PNG, res)
|
graph.Render(chart.PNG, f)
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/custom_formatters/output.png
Normal file
After Width: | Height: | Size: 29 KiB |
34
examples/custom_padding/main.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
|
"github.com/wcharczuk/go-chart/drawing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
graph := chart.Chart{
|
||||||
|
Background: chart.Style{
|
||||||
|
Padding: chart.Box{
|
||||||
|
Top: 50,
|
||||||
|
Left: 25,
|
||||||
|
Right: 25,
|
||||||
|
Bottom: 10,
|
||||||
|
},
|
||||||
|
FillColor: drawing.ColorFromHex("efefef"),
|
||||||
|
},
|
||||||
|
Series: []chart.Series{
|
||||||
|
chart.ContinuousSeries{
|
||||||
|
XValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(1.0).WithEnd(100.0)}.Values(),
|
||||||
|
YValues: chart.Seq{Sequence: chart.NewRandomSequence().WithLen(100).WithMin(100).WithMax(512)}.Values(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
f, _ := os.Create("output.png")
|
||||||
|
defer f.Close()
|
||||||
|
graph.Render(chart.PNG, f)
|
||||||
|
}
|
BIN
examples/custom_padding/output.png
Normal file
After Width: | Height: | Size: 65 KiB |
|
@ -1,12 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
//go:generate go run main.go
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
/*
|
/*
|
||||||
In this example we set a custom range for the y-axis, overriding the automatic range generation.
|
In this example we set a custom range for the y-axis, overriding the automatic range generation.
|
||||||
Note: the chart will still generate the ticks automatically based on the custom range, so the intervals may be a bit weird.
|
Note: the chart will still generate the ticks automatically based on the custom range, so the intervals may be a bit weird.
|
||||||
|
@ -14,7 +16,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
YAxis: chart.YAxis{
|
YAxis: chart.YAxis{
|
||||||
Style: chart.StyleShow(),
|
|
||||||
Range: &chart.ContinuousRange{
|
Range: &chart.ContinuousRange{
|
||||||
Min: 0.0,
|
Min: 0.0,
|
||||||
Max: 10.0,
|
Max: 10.0,
|
||||||
|
@ -27,12 +28,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
f, _ := os.Create("output.png")
|
||||||
res.Header().Set("Content-Type", "image/png")
|
defer f.Close()
|
||||||
graph.Render(chart.PNG, res)
|
graph.Render(chart.PNG, f)
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/custom_ranges/output.png
Normal file
After Width: | Height: | Size: 20 KiB |
|
@ -1,13 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
//go:generate go run main.go
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
/*
|
/*
|
||||||
In this example we set some custom colors for the series and the chart background and canvas.
|
In this example we set some custom colors for the series and the chart background and canvas.
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +23,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
chart.ContinuousSeries{
|
chart.ContinuousSeries{
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true, //note; if we set ANY other properties, we must set this to true.
|
|
||||||
StrokeColor: drawing.ColorRed, // will supercede defaults
|
StrokeColor: drawing.ColorRed, // will supercede defaults
|
||||||
FillColor: drawing.ColorRed.WithAlpha(64), // will supercede defaults
|
FillColor: drawing.ColorRed.WithAlpha(64), // will supercede defaults
|
||||||
},
|
},
|
||||||
|
@ -31,11 +32,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/custom_styles/output.png
Normal file
After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 987 B After Width: | Height: | Size: 987 B |
|
@ -1,12 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
//go:generate go run main.go
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
/*
|
/*
|
||||||
In this example we set a custom set of ticks to use for the y-axis. It can be (almost) whatever you want, including some custom labels for ticks.
|
In this example we set a custom set of ticks to use for the y-axis. It can be (almost) whatever you want, including some custom labels for ticks.
|
||||||
Custom ticks will supercede a custom range, which will supercede automatic generation based on series values.
|
Custom ticks will supercede a custom range, which will supercede automatic generation based on series values.
|
||||||
|
@ -14,7 +16,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
YAxis: chart.YAxis{
|
YAxis: chart.YAxis{
|
||||||
Style: chart.StyleShow(),
|
|
||||||
Range: &chart.ContinuousRange{
|
Range: &chart.ContinuousRange{
|
||||||
Min: 0.0,
|
Min: 0.0,
|
||||||
Max: 4.0,
|
Max: 4.0,
|
||||||
|
@ -35,12 +36,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
f, _ := os.Create("output.png")
|
||||||
res.Header().Set("Content-Type", "image/png")
|
defer f.Close()
|
||||||
graph.Render(chart.PNG, res)
|
graph.Render(chart.PNG, f)
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/custom_ticks/output.png
Normal file
After Width: | Height: | Size: 17 KiB |
|
@ -1,12 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"os"
|
||||||
|
|
||||||
"github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The below will draw the same chart as the `basic` example, except with both the x and y axes turned on.
|
The below will draw the same chart as the `basic` example, except with both the x and y axes turned on.
|
||||||
|
@ -19,14 +21,12 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
Height: 500,
|
Height: 500,
|
||||||
Width: 500,
|
Width: 500,
|
||||||
XAxis: chart.XAxis{
|
XAxis: chart.XAxis{
|
||||||
Style: chart.StyleShow(),
|
|
||||||
/*Range: &chart.ContinuousRange{
|
/*Range: &chart.ContinuousRange{
|
||||||
Descending: true,
|
Descending: true,
|
||||||
},*/
|
},*/
|
||||||
},
|
},
|
||||||
YAxis: chart.YAxis{
|
YAxis: chart.YAxis{
|
||||||
Style: chart.StyleShow(),
|
|
||||||
Range: &chart.ContinuousRange{
|
Range: &chart.ContinuousRange{
|
||||||
Descending: true,
|
Descending: true,
|
||||||
},
|
},
|
||||||
|
@ -34,7 +34,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
chart.ContinuousSeries{
|
chart.ContinuousSeries{
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
|
||||||
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
|
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
|
||||||
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
|
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
|
||||||
},
|
},
|
||||||
|
@ -44,11 +43,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/descending/output.png
Normal file
After Width: | Height: | Size: 19 KiB |
28
examples/donut_chart/main.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pie := chart.DonutChart{
|
||||||
|
Width: 512,
|
||||||
|
Height: 512,
|
||||||
|
Values: []chart.Value{
|
||||||
|
{Value: 5, Label: "Blue"},
|
||||||
|
{Value: 5, Label: "Green"},
|
||||||
|
{Value: 4, Label: "Gray"},
|
||||||
|
{Value: 4, Label: "Orange"},
|
||||||
|
{Value: 3, Label: "Deep Blue"},
|
||||||
|
{Value: 3, Label: "test"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
f, _ := os.Create("output.png")
|
||||||
|
defer f.Close()
|
||||||
|
pie.Render(chart.PNG, f)
|
||||||
|
}
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
|
@ -1,12 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
In this example we add a `Renderable` or a custom component to the `Elements` array.
|
In this example we add a `Renderable` or a custom component to the `Elements` array.
|
||||||
|
@ -15,12 +17,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
XAxis: chart.XAxis{
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
YAxis: chart.YAxis{
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
Background: chart.Style{
|
Background: chart.Style{
|
||||||
Padding: chart.Box{
|
Padding: chart.Box{
|
||||||
Top: 20,
|
Top: 20,
|
||||||
|
@ -41,11 +37,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
chart.Legend(&graph),
|
chart.Legend(&graph),
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/legend/output.png
Normal file
After Width: | Height: | Size: 24 KiB |
|
@ -1,12 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
//go:generate go run main.go
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
In this example we add a `Renderable` or a custom component to the `Elements` array.
|
In this example we add a `Renderable` or a custom component to the `Elements` array.
|
||||||
|
@ -15,12 +17,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
XAxis: chart.XAxis{
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
YAxis: chart.YAxis{
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
Background: chart.Style{
|
Background: chart.Style{
|
||||||
Padding: chart.Box{
|
Padding: chart.Box{
|
||||||
Top: 20,
|
Top: 20,
|
||||||
|
@ -101,11 +97,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
chart.LegendLeft(&graph),
|
chart.LegendLeft(&graph),
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/legend_left/output.png
Normal file
After Width: | Height: | Size: 44 KiB |
|
@ -1,13 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart"
|
||||||
"github.com/wcharczuk/go-chart/seq"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
In this example we add a new type of series, a `SimpleMovingAverageSeries` that takes another series as a required argument.
|
In this example we add a new type of series, a `SimpleMovingAverageSeries` that takes another series as a required argument.
|
||||||
|
@ -16,8 +17,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
mainSeries := chart.ContinuousSeries{
|
mainSeries := chart.ContinuousSeries{
|
||||||
Name: "A test series",
|
Name: "A test series",
|
||||||
XValues: SeqRange(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
XValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(1.0).WithEnd(100.0)}.Values(), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||||
YValues: seq.RandomValuesWithMax(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
YValues: chart.Seq{Sequence: chart.NewRandomSequence().WithLen(100).WithMin(0).WithMax(100)}.Values(), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
||||||
}
|
}
|
||||||
|
|
||||||
// note we create a LinearRegressionSeries series by assignin the inner series.
|
// note we create a LinearRegressionSeries series by assignin the inner series.
|
||||||
|
@ -33,11 +34,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/linear_regression/output.png
Normal file
After Width: | Height: | Size: 71 KiB |
|
@ -1,22 +1,22 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
//go:generate go run main.go
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
import (
|
||||||
"github.com/wcharczuk/go-chart/seq"
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
mainSeries := chart.ContinuousSeries{
|
mainSeries := chart.ContinuousSeries{
|
||||||
Name: "A test series",
|
Name: "A test series",
|
||||||
XValues: SeqRange(1.0, 100.0),
|
XValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(1.0).WithEnd(100.0)}.Values(),
|
||||||
YValues: seq.New(seq.NewRandom().WithLen(100).WithMax(150).WithMin(50)).Array(),
|
YValues: chart.Seq{Sequence: chart.NewRandomSequence().WithLen(100).WithMin(50).WithMax(150)}.Values(),
|
||||||
}
|
}
|
||||||
|
|
||||||
minSeries := &chart.MinSeries{
|
minSeries := &chart.MinSeries{
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
|
||||||
StrokeColor: chart.ColorAlternateGray,
|
StrokeColor: chart.ColorAlternateGray,
|
||||||
StrokeDashArray: []float64{5.0, 5.0},
|
StrokeDashArray: []float64{5.0, 5.0},
|
||||||
},
|
},
|
||||||
|
@ -25,7 +25,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
maxSeries := &chart.MaxSeries{
|
maxSeries := &chart.MaxSeries{
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
|
||||||
StrokeColor: chart.ColorAlternateGray,
|
StrokeColor: chart.ColorAlternateGray,
|
||||||
StrokeDashArray: []float64{5.0, 5.0},
|
StrokeDashArray: []float64{5.0, 5.0},
|
||||||
},
|
},
|
||||||
|
@ -36,35 +35,27 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
Width: 1920,
|
Width: 1920,
|
||||||
Height: 1080,
|
Height: 1080,
|
||||||
YAxis: chart.YAxis{
|
YAxis: chart.YAxis{
|
||||||
Name: "Random Values",
|
Name: "Random Values",
|
||||||
NameStyle: chart.StyleShow(),
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
Range: &chart.ContinuousRange{
|
Range: &chart.ContinuousRange{
|
||||||
Min: 25,
|
Min: 25,
|
||||||
Max: 175,
|
Max: 175,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
XAxis: chart.XAxis{
|
XAxis: chart.XAxis{
|
||||||
Name: "Random Other Values",
|
Name: "Random Other Values",
|
||||||
NameStyle: chart.StyleShow(),
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
},
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
mainSeries,
|
mainSeries,
|
||||||
minSeries,
|
minSeries,
|
||||||
maxSeries,
|
maxSeries,
|
||||||
chart.LastValueAnnotation(minSeries),
|
chart.LastValueAnnotationSeries(minSeries),
|
||||||
chart.LastValueAnnotation(maxSeries),
|
chart.LastValueAnnotationSeries(maxSeries),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
graph.Elements = []chart.Renderable{chart.Legend(&graph)}
|
graph.Elements = []chart.Renderable{chart.Legend(&graph)}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/min_max/output.png
Normal file
After Width: | Height: | Size: 168 KiB |
29
examples/pie_chart/main.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pie := chart.PieChart{
|
||||||
|
Width: 512,
|
||||||
|
Height: 512,
|
||||||
|
Values: []chart.Value{
|
||||||
|
{Value: 5, Label: "Blue"},
|
||||||
|
{Value: 5, Label: "Green"},
|
||||||
|
{Value: 4, Label: "Gray"},
|
||||||
|
{Value: 4, Label: "Orange"},
|
||||||
|
{Value: 3, Label: "Deep Blue"},
|
||||||
|
{Value: 3, Label: "??"},
|
||||||
|
{Value: 1, Label: "!!"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
f, _ := os.Create("output.png")
|
||||||
|
defer f.Close()
|
||||||
|
pie.Render(chart.PNG, f)
|
||||||
|
}
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 565 B After Width: | Height: | Size: 565 B |
|
@ -1,13 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
chart "github.com/wcharczuk/go-chart"
|
||||||
"github.com/wcharczuk/go-chart/seq"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
In this example we add a new type of series, a `PolynomialRegressionSeries` that takes another series as a required argument.
|
In this example we add a new type of series, a `PolynomialRegressionSeries` that takes another series as a required argument.
|
||||||
|
@ -16,8 +17,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
mainSeries := chart.ContinuousSeries{
|
mainSeries := chart.ContinuousSeries{
|
||||||
Name: "A test series",
|
Name: "A test series",
|
||||||
XValues: SeqRange(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
XValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(1.0).WithEnd(100.0)}.Values(), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||||
YValues: seq.RandomValuesWithMax(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
YValues: chart.Seq{Sequence: chart.NewRandomSequence().WithLen(100).WithMin(0).WithMax(100)}.Values(), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
||||||
}
|
}
|
||||||
|
|
||||||
polyRegSeries := &chart.PolynomialRegressionSeries{
|
polyRegSeries := &chart.PolynomialRegressionSeries{
|
||||||
|
@ -32,11 +33,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/poly_regression/output.png
Normal file
After Width: | Height: | Size: 76 KiB |
|
@ -1,14 +1,22 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
log := chart.NewLogger()
|
||||||
|
drawChart(log)
|
||||||
|
}
|
||||||
|
|
||||||
func parseInt(str string) int {
|
func parseInt(str string) int {
|
||||||
v, _ := strconv.Atoi(str)
|
v, _ := strconv.Atoi(str)
|
||||||
return v
|
return v
|
||||||
|
@ -110,24 +118,16 @@ func drawChart(log chart.Logger) http.HandlerFunc {
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
mainSeries,
|
mainSeries,
|
||||||
linreg,
|
linreg,
|
||||||
chart.LastValueAnnotation(linreg),
|
chart.LastValueAnnotationSeries(linreg),
|
||||||
sma,
|
sma,
|
||||||
chart.LastValueAnnotation(sma),
|
chart.LastValueAnnotationSeries(sma),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
graph.Elements = []chart.Renderable{chart.LegendThin(&graph)}
|
graph.Elements = []chart.Renderable{chart.LegendThin(&graph)}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", chart.ContentTypePNG)
|
f, _ := os.Create("output.png")
|
||||||
if err := graph.Render(chart.PNG, res); err != nil {
|
defer f.Close()
|
||||||
log.Err(err)
|
graph.Render(chart.PNG, f)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
|
||||||
log := chart.NewLogger()
|
|
||||||
log.Infof("listening on :8080")
|
|
||||||
http.HandleFunc("/", drawChart(log))
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
|
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
|
@ -6,7 +6,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
var lock sync.Mutex
|
var lock sync.Mutex
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,13 +20,12 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
chart.ContinuousSeries{
|
chart.ContinuousSeries{
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
|
||||||
StrokeWidth: chart.Disabled,
|
StrokeWidth: chart.Disabled,
|
||||||
DotWidth: 5,
|
DotWidth: 5,
|
||||||
DotColorProvider: viridisByY,
|
DotColorProvider: viridisByY,
|
||||||
},
|
},
|
||||||
XValues: chart.SeqRange(0, 127),
|
XValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(0).WithEnd(127)}.Values(),
|
||||||
YValues: chart.NewSeq(chart.NewSeqRandom().WithLen(128).WithMax(1024)).Values(),
|
YValues: chart.Seq{Sequence: chart.NewRandomSequence().WithLen(128).WithMin(0).WithMax(1024)}.Values(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -50,8 +49,8 @@ func unit(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
chart.ContinuousSeries{
|
chart.ContinuousSeries{
|
||||||
XValues: chart.SeqRangeWithStep(0, 4, 1),
|
XValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(0).WithEnd(4)}.Values(),
|
||||||
YValues: chart.SeqRangeWithStep(0, 4, 1),
|
YValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(0).WithEnd(4)}.Values(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
@ -1,17 +1,18 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
//go:generate go run main.go
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
|
|
||||||
mainSeries := chart.ContinuousSeries{
|
mainSeries := chart.ContinuousSeries{
|
||||||
Name: "A test series",
|
Name: "A test series",
|
||||||
XValues: chart.SeqRange(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
XValues: chart.Seq{Sequence: chart.NewLinearSequence().WithStart(1.0).WithEnd(100.0)}.Values(), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||||
YValues: chart.SeqRandomValuesWithMax(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
YValues: chart.Seq{Sequence: chart.NewRandomSequence().WithLen(100).WithMin(0).WithMax(100)}.Values(), //generates a []float64 randomly from 0 to 100 with 100 elements.
|
||||||
}
|
}
|
||||||
|
|
||||||
// note we create a SimpleMovingAverage series by assignin the inner series.
|
// note we create a SimpleMovingAverage series by assignin the inner series.
|
||||||
|
@ -27,11 +28,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
BIN
examples/simple_moving_average/output.png
Normal file
After Width: | Height: | Size: 80 KiB |
|
@ -1,25 +1,20 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"os"
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
sbc := chart.StackedBarChart{
|
sbc := chart.StackedBarChart{
|
||||||
Title: "Test Stacked Bar Chart",
|
Title: "Test Stacked Bar Chart",
|
||||||
TitleStyle: chart.StyleShow(),
|
|
||||||
Background: chart.Style{
|
Background: chart.Style{
|
||||||
Padding: chart.Box{
|
Padding: chart.Box{
|
||||||
Top: 40,
|
Top: 40,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Height: 512,
|
Height: 512,
|
||||||
XAxis: chart.StyleShow(),
|
|
||||||
YAxis: chart.StyleShow(),
|
|
||||||
Bars: []chart.StackedBar{
|
Bars: []chart.StackedBar{
|
||||||
{
|
{
|
||||||
Name: "This is a very long string to test word break wrapping.",
|
Name: "This is a very long string to test word break wrapping.",
|
||||||
|
@ -52,14 +47,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
err := sbc.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
if err != nil {
|
sbc.Render(chart.PNG, f)
|
||||||
fmt.Printf("Error rendering chart: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
||||||
}
|
}
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
@ -1,14 +1,16 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
xv, yv := xvalues(), yvalues()
|
xv, yv := xvalues(), yvalues()
|
||||||
|
|
||||||
priceSeries := chart.TimeSeries{
|
priceSeries := chart.TimeSeries{
|
||||||
|
@ -55,8 +57,9 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
|
graph.Render(chart.PNG, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func xvalues() []time.Time {
|
func xvalues() []time.Time {
|
||||||
|
@ -73,8 +76,3 @@ func xvalues() []time.Time {
|
||||||
func yvalues() []float64 {
|
func yvalues() []float64 {
|
||||||
return []float64{212.47, 212.59, 211.76, 211.37, 210.18, 208.00, 206.79, 209.33, 210.77, 210.82, 210.50, 209.79, 209.38, 210.07, 208.35, 207.95, 210.57, 208.66, 208.92, 208.66, 209.42, 210.59, 209.98, 208.32, 203.97, 197.83, 189.50, 187.27, 194.46, 199.27, 199.28, 197.67, 191.77, 195.41, 195.55, 192.59, 197.43, 194.79, 195.85, 196.74, 196.01, 198.45, 200.18, 199.73, 195.45, 196.46, 193.90, 193.60, 192.90, 192.87, 188.01, 188.12, 191.63, 192.13, 195.00, 198.47, 197.79, 199.41, 201.21, 201.33, 201.52, 200.25, 199.29, 202.35, 203.27, 203.37, 203.11, 201.85, 205.26, 207.51, 207.00, 206.60, 208.95, 208.83, 207.93, 210.39, 211.00, 210.36, 210.15, 210.04, 208.08, 208.56, 207.74, 204.84, 202.54, 205.62, 205.47, 208.73, 208.55, 209.31, 209.07, 209.35, 209.32, 209.56, 208.69, 210.68, 208.53, 205.61, 209.62, 208.35, 206.95, 205.34, 205.87, 201.88, 202.90, 205.03, 208.03, 204.86, 200.02, 201.67, 203.50, 206.02, 205.68, 205.21, 207.40, 205.93, 203.87, 201.02, 201.36, 198.82, 194.05, 191.92, 192.11, 193.66, 188.83, 191.93, 187.81, 188.06, 185.65, 186.69, 190.52, 187.64, 190.20, 188.13, 189.11, 193.72, 193.65, 190.16, 191.30, 191.60, 187.95, 185.42, 185.43, 185.27, 182.86, 186.63, 189.78, 192.88, 192.09, 192.00, 194.78, 192.32, 193.20, 195.54, 195.09, 193.56, 198.11, 199.00, 199.78, 200.43, 200.59, 198.40, 199.38, 199.54, 202.76, 202.50, 202.17, 203.34, 204.63, 204.38, 204.67, 204.56, 203.21, 203.12, 203.24, 205.12, 206.02, 205.52, 206.92, 206.25, 204.19, 206.42, 203.95, 204.50, 204.02, 205.92, 208.00, 208.01, 207.78, 209.24, 209.90, 210.10, 208.97, 208.97, 208.61, 208.92, 209.35, 207.45, 206.33, 207.97, 206.16, 205.01, 204.97, 205.72, 205.89, 208.45, 206.50, 206.56, 204.76, 206.78, 204.85, 204.91, 204.20, 205.49, 205.21, 207.87, 209.28, 209.34, 210.24, 209.84, 210.27, 210.91, 210.28, 211.35, 211.68, 212.37, 212.08, 210.07, 208.45, 208.04, 207.75, 208.37, 206.52, 207.85, 208.44, 208.10, 210.81, 203.24, 199.60, 203.20, 206.66, 209.48, 209.92, 208.41, 209.66, 209.53, 212.65, 213.40, 214.95, 214.92, 216.12, 215.83}
|
return []float64{212.47, 212.59, 211.76, 211.37, 210.18, 208.00, 206.79, 209.33, 210.77, 210.82, 210.50, 209.79, 209.38, 210.07, 208.35, 207.95, 210.57, 208.66, 208.92, 208.66, 209.42, 210.59, 209.98, 208.32, 203.97, 197.83, 189.50, 187.27, 194.46, 199.27, 199.28, 197.67, 191.77, 195.41, 195.55, 192.59, 197.43, 194.79, 195.85, 196.74, 196.01, 198.45, 200.18, 199.73, 195.45, 196.46, 193.90, 193.60, 192.90, 192.87, 188.01, 188.12, 191.63, 192.13, 195.00, 198.47, 197.79, 199.41, 201.21, 201.33, 201.52, 200.25, 199.29, 202.35, 203.27, 203.37, 203.11, 201.85, 205.26, 207.51, 207.00, 206.60, 208.95, 208.83, 207.93, 210.39, 211.00, 210.36, 210.15, 210.04, 208.08, 208.56, 207.74, 204.84, 202.54, 205.62, 205.47, 208.73, 208.55, 209.31, 209.07, 209.35, 209.32, 209.56, 208.69, 210.68, 208.53, 205.61, 209.62, 208.35, 206.95, 205.34, 205.87, 201.88, 202.90, 205.03, 208.03, 204.86, 200.02, 201.67, 203.50, 206.02, 205.68, 205.21, 207.40, 205.93, 203.87, 201.02, 201.36, 198.82, 194.05, 191.92, 192.11, 193.66, 188.83, 191.93, 187.81, 188.06, 185.65, 186.69, 190.52, 187.64, 190.20, 188.13, 189.11, 193.72, 193.65, 190.16, 191.30, 191.60, 187.95, 185.42, 185.43, 185.27, 182.86, 186.63, 189.78, 192.88, 192.09, 192.00, 194.78, 192.32, 193.20, 195.54, 195.09, 193.56, 198.11, 199.00, 199.78, 200.43, 200.59, 198.40, 199.38, 199.54, 202.76, 202.50, 202.17, 203.34, 204.63, 204.38, 204.67, 204.56, 203.21, 203.12, 203.24, 205.12, 206.02, 205.52, 206.92, 206.25, 204.19, 206.42, 203.95, 204.50, 204.02, 205.92, 208.00, 208.01, 207.78, 209.24, 209.90, 210.10, 208.97, 208.97, 208.61, 208.92, 209.35, 207.45, 206.33, 207.97, 206.16, 205.01, 204.97, 205.72, 205.89, 208.45, 206.50, 206.56, 204.76, 206.78, 204.85, 204.91, 204.20, 205.49, 205.21, 207.87, 209.28, 209.34, 210.24, 209.84, 210.27, 210.91, 210.28, 211.35, 211.68, 212.37, 212.08, 210.07, 208.45, 208.04, 207.75, 208.37, 206.52, 207.85, 208.44, 208.10, 210.81, 203.24, 199.60, 203.20, 206.66, 209.48, 209.92, 208.41, 209.66, 209.53, 212.65, 213.40, 214.95, 214.92, 216.12, 215.83}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
|
BIN
examples/stock_analysis/output.png
Normal file
After Width: | Height: | Size: 66 KiB |
|
@ -1,13 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
//go:generate go run main.go
|
||||||
"net/http"
|
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/wcharczuk/go-chart"
|
||||||
"github.com/wcharczuk/go-chart/drawing"
|
"github.com/wcharczuk/go-chart/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
f, _ := chart.GetDefaultFont()
|
f, _ := chart.GetDefaultFont()
|
||||||
r, _ := chart.PNG(1024, 1024)
|
r, _ := chart.PNG(1024, 1024)
|
||||||
|
|
||||||
|
@ -43,11 +45,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
StrokeWidth: 2,
|
StrokeWidth: 2,
|
||||||
})
|
})
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
file, _ := os.Create("output.png")
|
||||||
r.Save(res)
|
defer file.Close()
|
||||||
}
|
r.Save(file)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
|
@ -13,9 +13,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
Note: chart.TimeSeries implements `ValueFormatterProvider` and as a result gives the XAxis the appropriate formatter to use for the ticks.
|
Note: chart.TimeSeries implements `ValueFormatterProvider` and as a result gives the XAxis the appropriate formatter to use for the ticks.
|
||||||
*/
|
*/
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
XAxis: chart.XAxis{
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
chart.TimeSeries{
|
chart.TimeSeries{
|
||||||
XValues: []time.Time{
|
XValues: []time.Time{
|
||||||
|
@ -46,7 +43,6 @@ func drawCustomChart(res http.ResponseWriter, req *http.Request) {
|
||||||
*/
|
*/
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
XAxis: chart.XAxis{
|
XAxis: chart.XAxis{
|
||||||
Style: chart.StyleShow(),
|
|
||||||
ValueFormatter: chart.TimeHourValueFormatter,
|
ValueFormatter: chart.TimeHourValueFormatter,
|
||||||
},
|
},
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
@ -1,13 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
func main() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
In this example we add a second series, and assign it to the secondary y axis, giving that series it's own range.
|
In this example we add a second series, and assign it to the secondary y axis, giving that series it's own range.
|
||||||
|
@ -17,7 +19,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
XAxis: chart.XAxis{
|
XAxis: chart.XAxis{
|
||||||
Style: chart.StyleShow(), //enables / displays the x-axis
|
|
||||||
TickPosition: chart.TickPositionBetweenTicks,
|
TickPosition: chart.TickPositionBetweenTicks,
|
||||||
ValueFormatter: func(v interface{}) string {
|
ValueFormatter: func(v interface{}) string {
|
||||||
typed := v.(float64)
|
typed := v.(float64)
|
||||||
|
@ -25,12 +26,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
return fmt.Sprintf("%d-%d\n%d", typedDate.Month(), typedDate.Day(), typedDate.Year())
|
return fmt.Sprintf("%d-%d\n%d", typedDate.Month(), typedDate.Day(), typedDate.Year())
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
YAxis: chart.YAxis{
|
|
||||||
Style: chart.StyleShow(), //enables / displays the y-axis
|
|
||||||
},
|
|
||||||
YAxisSecondary: chart.YAxis{
|
|
||||||
Style: chart.StyleShow(), //enables / displays the secondary y-axis
|
|
||||||
},
|
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
||||||
chart.ContinuousSeries{
|
chart.ContinuousSeries{
|
||||||
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
|
||||||
|
@ -44,11 +39,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Header().Set("Content-Type", "image/png")
|
f, _ := os.Create("output.png")
|
||||||
graph.Render(chart.PNG, res)
|
defer f.Close()
|
||||||
}
|
graph.Render(chart.PNG, f)
|
||||||
|
|
||||||
func main() {
|
|
||||||
http.HandleFunc("/", drawChart)
|
|
||||||
http.ListenAndServe(":8080", nil)
|
|
||||||
}
|
}
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
|
@ -1,28 +1,27 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
//go:generate go run main.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
chart "github.com/wcharczuk/go-chart"
|
"github.com/wcharczuk/go-chart"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
var b float64
|
var b float64
|
||||||
b = 1000
|
b = 1000
|
||||||
|
|
||||||
ts1 := chart.ContinuousSeries{ //TimeSeries{
|
ts1 := chart.ContinuousSeries{ //TimeSeries{
|
||||||
Name: "Time Series",
|
Name: "Time Series",
|
||||||
Style: chart.StyleShow(),
|
|
||||||
XValues: []float64{10 * b, 20 * b, 30 * b, 40 * b, 50 * b, 60 * b, 70 * b, 80 * b},
|
XValues: []float64{10 * b, 20 * b, 30 * b, 40 * b, 50 * b, 60 * b, 70 * b, 80 * b},
|
||||||
YValues: []float64{1.0, 2.0, 30.0, 4.0, 50.0, 6.0, 7.0, 88.0},
|
YValues: []float64{1.0, 2.0, 30.0, 4.0, 50.0, 6.0, 7.0, 88.0},
|
||||||
}
|
}
|
||||||
|
|
||||||
ts2 := chart.ContinuousSeries{ //TimeSeries{
|
ts2 := chart.ContinuousSeries{ //TimeSeries{
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
|
||||||
StrokeColor: chart.GetDefaultColor(1),
|
StrokeColor: chart.GetDefaultColor(1),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -34,15 +33,11 @@ func main() {
|
||||||
|
|
||||||
XAxis: chart.XAxis{
|
XAxis: chart.XAxis{
|
||||||
Name: "The XAxis",
|
Name: "The XAxis",
|
||||||
NameStyle: chart.StyleShow(),
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
ValueFormatter: chart.TimeMinuteValueFormatter, //TimeHourValueFormatter,
|
ValueFormatter: chart.TimeMinuteValueFormatter, //TimeHourValueFormatter,
|
||||||
},
|
},
|
||||||
|
|
||||||
YAxis: chart.YAxis{
|
YAxis: chart.YAxis{
|
||||||
Name: "The YAxis",
|
Name: "The YAxis",
|
||||||
NameStyle: chart.StyleShow(),
|
|
||||||
Style: chart.StyleShow(),
|
|
||||||
},
|
},
|
||||||
|
|
||||||
Series: []chart.Series{
|
Series: []chart.Series{
|
BIN
examples/twopoint/output.png
Normal file
After Width: | Height: | Size: 40 KiB |