can rotate text + add y axis names

This commit is contained in:
Will Charczuk 2016-08-06 21:59:46 -07:00
parent 3607d732d9
commit 718678b421
34 changed files with 102 additions and 20 deletions

View file

@ -1,47 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
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).
It is important to not that the chart automatically sizes the canvas box to fit the annotations,
As well as automatically assign a series color for the `Stroke` or border component of the series.
The annotation series is most often used by the original author to show the last value of another series, but
they can be used in other capacities as well.
*/
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},
},
chart.AnnotationSeries{
Annotations: []chart.Value2{
{XValue: 1.0, YValue: 1.0, Label: "One"},
{XValue: 2.0, YValue: 2.0, Label: "Two"},
{XValue: 3.0, YValue: 3.0, Label: "Three"},
{XValue: 4.0, YValue: 4.0, Label: "Four"},
{XValue: 5.0, YValue: 5.0, Label: "Five"},
},
},
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,47 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
The below will draw the same chart as the `basic` example, except with both the x and y axes turned on.
In this case, both the x and y axis ticks are generated automatically, the x and y ranges are established automatically, the canvas "box" is adjusted to fit the space the axes occupy so as not to clip.
*/
graph := chart.Chart{
XAxis: chart.XAxis{
Style: chart.Style{
Show: true, //enables / displays the x-axis
},
},
YAxis: chart.YAxis{
Style: chart.Style{
Show: true, //enables / displays the y-axis
},
},
Series: []chart.Series{
chart.ContinuousSeries{
Style: chart.Style{
Show: true,
StrokeColor: chart.GetDefaultColor(0).WithAlpha(64),
FillColor: chart.GetDefaultColor(0).WithAlpha(64),
},
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 main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,54 +0,0 @@
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
sbc := chart.BarChart{
Height: 512,
BarWidth: 60,
XAxis: chart.Style{
Show: true,
},
YAxis: chart.YAxis{
Style: chart.Style{
Show: true,
},
},
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))
}

View file

@ -1,42 +0,0 @@
package main
import (
"net/http"
"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, 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 main() {
http.HandleFunc("/", drawChart)
http.HandleFunc("/wide", drawChartWide)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,44 +0,0 @@
package main
import (
"fmt"
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
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.
This example also shows what the chart looks like with the x-axis left off or not shown.
*/
graph := chart.Chart{
YAxis: chart.YAxis{
Style: chart.Style{
Show: true,
},
ValueFormatter: func(v interface{}) string {
if vf, isFloat := v.(float64); isFloat {
return fmt.Sprintf("%0.6f", vf)
}
return ""
},
},
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 main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,74 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
"github.com/wcharczuk/go-chart/drawing"
)
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.Style{
Show: true,
},
},
YAxis: chart.YAxis{
Style: chart.Style{
Show: true,
},
},
Series: []chart.Series{
chart.ContinuousSeries{
XValues: chart.Sequence.Float64(1.0, 100.0),
YValues: chart.Sequence.Random(100.0, 256.0),
},
},
}
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.Style{
Show: true,
},
},
YAxis: chart.YAxis{
Style: chart.Style{
Show: true,
},
},
Series: []chart.Series{
chart.ContinuousSeries{
XValues: chart.Sequence.Float64(1.0, 100.0),
YValues: chart.Sequence.Random(100.0, 256.0),
},
},
}
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)
}

View file

@ -1,40 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
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.
*/
graph := chart.Chart{
YAxis: chart.YAxis{
Style: chart.Style{
Show: true,
},
Range: &chart.ContinuousRange{
Min: 0.0,
Max: 10.0,
},
},
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 main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,41 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
"github.com/wcharczuk/go-chart/drawing"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
In this example we set some custom colors for the series and the chart background and canvas.
*/
graph := chart.Chart{
Background: chart.Style{
FillColor: drawing.ColorBlue,
},
Canvas: chart.Style{
FillColor: drawing.ColorFromHex("efefef"),
},
Series: []chart.Series{
chart.ContinuousSeries{
Style: chart.Style{
Show: true, //note; if we set ANY other properties, we must set this to true.
StrokeColor: drawing.ColorRed, // will supercede defaults
FillColor: drawing.ColorRed.WithAlpha(64), // will supercede defaults
},
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 main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,48 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
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.
*/
graph := chart.Chart{
YAxis: chart.YAxis{
Style: chart.Style{
Show: true,
},
Range: &chart.ContinuousRange{
Min: 0.0,
Max: 4.0,
},
Ticks: []chart.Tick{
{0.0, "0.00"},
{2.0, "2.00"},
{4.0, "4.00"},
{6.0, "6.00"},
{8.0, "Eight"},
{10.0, "Ten"},
},
},
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 main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,51 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
In this example we add a `Renderable` or a custom component to the `Elements` array.
In this specific case it is a pre-built renderable (`CreateLegend`) that draws a legend for the chart's series.
If you like, you can use `CreateLegend` as a template for writing your own renderable, or even your own legend.
*/
graph := chart.Chart{
XAxis: chart.XAxis{
Style: chart.Style{Show: true},
},
YAxis: chart.YAxis{
Style: chart.Style{Show: true},
},
Background: chart.Style{
Padding: chart.Box{
Top: 20,
Left: 20,
},
},
Series: []chart.Series{
chart.ContinuousSeries{
Name: "A test series",
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
},
},
}
//note we have to do this as a separate step because we need a reference to graph
graph.Elements = []chart.Renderable{
chart.Legend(&graph),
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,42 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
In this example we add a new type of series, a `SimpleMovingAverageSeries` that takes another series as a required argument.
InnerSeries only needs to implement `ValueProvider`, so really you could chain `SimpleMovingAverageSeries` together if you wanted.
*/
mainSeries := chart.ContinuousSeries{
Name: "A test series",
XValues: chart.Sequence.Float64(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
YValues: chart.Sequence.Random(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
}
// note we create a LinearRegressionSeries series by assignin the inner series.
// we need to use a reference because `.Render()` needs to modify state within the series.
linRegSeries := &chart.LinearRegressionSeries{
InnerSeries: mainSeries,
} // we can optionally set the `WindowSize` property which alters how the moving average is calculated.
graph := chart.Chart{
Series: []chart.Series{
mainSeries,
linRegSeries,
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,44 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
start := chart.Date.Date(2016, 7, 01, chart.Date.Eastern())
end := chart.Date.Date(2016, 07, 21, chart.Date.Eastern())
xv := chart.Sequence.MarketHours(start, end, chart.NYSEOpen, chart.NYSEClose, chart.Date.IsNYSEHoliday)
yv := chart.Sequence.RandomWithAverage(len(xv), 200, 10)
graph := chart.Chart{
XAxis: chart.XAxis{
Style: chart.StyleShow(),
TickPosition: chart.TickPositionBetweenTicks,
ValueFormatter: chart.TimeHourValueFormatter,
Range: &chart.MarketHoursRange{
MarketOpen: chart.NYSEOpen,
MarketClose: chart.NYSEClose,
HolidayProvider: chart.Date.IsNYSEHoliday,
},
},
YAxis: chart.YAxis{
Style: chart.StyleShow(),
},
Series: []chart.Series{
chart.TimeSeries{
XValues: xv,
YValues: yv,
},
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,61 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
mainSeries := chart.ContinuousSeries{
Name: "A test series",
XValues: chart.Sequence.Float64(1.0, 100.0),
YValues: chart.Sequence.RandomWithAverage(100, 100, 50),
}
minSeries := &chart.MinSeries{
Style: chart.Style{
Show: true,
StrokeColor: chart.ColorAlternateGray,
StrokeDashArray: []float64{5.0, 5.0},
},
InnerSeries: mainSeries,
}
maxSeries := &chart.MaxSeries{
Style: chart.Style{
Show: true,
StrokeColor: chart.ColorAlternateGray,
StrokeDashArray: []float64{5.0, 5.0},
},
InnerSeries: mainSeries,
}
graph := chart.Chart{
YAxis: chart.YAxis{
Style: chart.StyleShow(),
Range: &chart.ContinuousRange{
Min: 25,
Max: 175,
},
},
XAxis: chart.XAxis{
Style: chart.StyleShow(),
},
Series: []chart.Series{
mainSeries,
minSeries,
maxSeries,
chart.LastValueAnnotation(minSeries),
chart.LastValueAnnotation(maxSeries),
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,36 +0,0 @@
package main
import (
"fmt"
"log"
"net/http"
"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 main() {
http.HandleFunc("/", drawChart)
log.Fatal(http.ListenAndServe(":8080", nil))
}

View file

@ -1,294 +0,0 @@
package main
import (
"bufio"
"bytes"
"fmt"
"net/http"
"strconv"
"strings"
"time"
"github.com/wcharczuk/go-chart"
"github.com/wcharczuk/go-chart/drawing"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
xv, yv := data()
times := chart.TimeSeries{
Name: "Elapsed ms",
XValues: xv,
YValues: yv,
}
tma := chart.SMASeries{
Style: chart.Style{
Show: true,
StrokeColor: drawing.ColorRed,
StrokeDashArray: []float64{5.0, 5.0},
},
InnerSeries: times,
Period: 50,
}
graph := chart.Chart{
XAxis: chart.XAxis{
Style: chart.Style{Show: true},
ValueFormatter: chart.TimeMinuteValueFormatter,
},
YAxis: chart.YAxis{
Style: chart.Style{Show: true},
ValueFormatter: func(v interface{}) string {
if typed, isTyped := v.(float64); isTyped {
return fmt.Sprintf("%0.2fms", typed)
}
return ""
},
},
Series: []chart.Series{
times,
tma,
},
}
res.Header().Set("Content-Type", "image/svg+xml")
graph.Render(chart.SVG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}
func data() ([]time.Time, []float64) {
var timestamps []time.Time
var elapsed []float64
scanner := bufio.NewScanner(bytes.NewBuffer([]byte(rawData)))
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
pieces := strings.Split(scanner.Text(), ",")
hour, _ := strconv.Atoi(pieces[0])
minute, _ := strconv.Atoi(pieces[1])
second, _ := strconv.Atoi(pieces[2])
now := time.Now().UTC()
timestamps = append(timestamps, time.Date(now.Year(), now.Month(), now.Day(), hour, minute, second, 0, time.UTC))
parsedElapsed, err := strconv.ParseFloat(pieces[3], 64)
if err == nil {
elapsed = append(elapsed, parsedElapsed/1000.0)
} else {
println(err.Error())
}
}
return timestamps, elapsed
}
var (
rawData = `19,39,18,12667.583333333333
19,39,19,8027.0000000000000000
19,39,20,12562.857142857143
19,39,22,8724.8000000000000000
19,39,25,10162.7500000000000000
19,39,27,11827.0000000000000000
19,39,28,9618.1000000000000000
19,39,29,13576.818181818182
19,39,30,15887.750000000000
19,39,31,10618.2500000000000000
19,39,36,10933.7142857142857143
19,39,37,6867.0000000000000000
19,39,38,10123.8461538461538462
19,39,39,6610.0000000000000000
19,39,41,12300.000000000000
19,39,44,11224.7500000000000000
19,39,45,10408.2500000000000000
19,39,46,11958.5000000000000000
19,39,47,12380.000000000000
19,39,49,12254.5000000000000000
19,39,50,11668.2500000000000000
19,39,51,8328.0000000000000000
19,39,52,8662.0000000000000000
19,39,53,8210.0000000000000000
19,39,55,7966.5000000000000000
19,39,56,7199.0000000000000000
19,39,57,8827.9411764705882353
19,39,58,10015.4000000000000000
19,39,59,10315.5000000000000000
19,40,0,7072.0000000000000000
19,40,1,10165.3333333333333333
19,40,2,8491.7500000000000000
19,40,4,7943.5000000000000000
19,40,6,7833.8333333333333333
19,40,7,8368.0000000000000000
19,40,10,7771.1428571428571429
19,40,11,7342.0000000000000000
19,40,12,8838.0000000000000000
19,40,13,8859.0000000000000000
19,40,14,9342.0000000000000000
19,40,15,9068.5000000000000000
19,40,16,9038.8333333333333333
19,40,17,10534.5000000000000000
19,40,18,11313.375000000000
19,40,19,11042.5000000000000000
19,40,20,9595.6666666666666667
19,40,21,9488.0714285714285714
19,40,22,9494.9523809523809524
19,40,23,8496.3000000000000000
19,40,24,8383.0000000000000000
19,40,25,12987.000000000000
19,40,26,9842.0909090909090909
19,40,27,11258.625000000000
19,40,28,8300.4000000000000000
19,40,29,7879.3333333333333333
19,40,30,7080.0000000000000000
19,40,31,10902.0000000000000000
19,40,32,12349.0000000000000000
19,40,33,6883.5000000000000000
19,40,35,10097.6666666666666667
19,40,36,9014.7000000000000000
19,40,37,8808.6000000000000000
19,40,38,10870.0000000000000000
19,40,39,8465.5000000000000000
19,40,41,8491.5000000000000000
19,40,42,7662.7500000000000000
19,40,43,7608.8333333333333333
19,40,44,7739.5000000000000000
19,40,45,10960.916666666667
19,40,46,7899.1111111111111111
19,40,47,9148.0000000000000000
19,40,48,7699.5000000000000000
19,40,50,6846.5000000000000000
19,40,51,8368.0000000000000000
19,40,52,8289.8750000000000000
19,40,53,10589.2500000000000000
19,40,54,11763.0000000000000000
19,40,55,6925.5000000000000000
19,40,56,7717.5000000000000000
19,40,58,11074.5000000000000000
19,41,0,9444.5000000000000000
19,41,1,9895.5000000000000000
19,41,2,9601.5000000000000000
19,42,0,3358.5000000000000000
19,42,1,8377.5454545454545455
19,42,2,8457.5000000000000000
19,42,3,11676.0000000000000000
19,42,7,9066.5000000000000000
19,42,10,8528.5000000000000000
19,42,11,9981.3333333333333333
19,42,13,9923.1666666666666667
19,42,15,11943.0000000000000000
19,42,17,9073.5000000000000000
19,42,18,11792.0000000000000000
19,42,19,7716.7500000000000000
19,42,20,10501.4166666666666667
19,42,21,7109.5000000000000000
19,42,22,17030.166666666667
19,42,24,6466.0000000000000000
19,42,25,7661.5000000000000000
19,42,26,9274.7142857142857143
19,42,27,10534.6666666666666667
19,42,30,3491.0000000000000000
19,42,31,8535.8000000000000000
19,42,32,13026.666666666667
19,42,33,13179.500000000000
19,42,34,6155.0000000000000000
19,42,35,34231.125000000000
19,42,36,12951.0000000000000000
19,42,38,10411.7000000000000000
19,42,40,6747.2000000000000000
19,42,41,15279.875000000000
19,42,42,12241.166666666667
19,42,43,11893.500000000000
19,42,44,9098.9166666666666667
19,42,45,12216.000000000000
19,42,46,11550.0000000000000000
19,42,47,20060.555555555556
19,42,55,5052.5000000000000000
19,42,56,11508.583333333333
19,42,57,10053.4000000000000000
19,42,58,9173.4444444444444444
19,42,59,13186.333333333333
19,43,0,9756.2000000000000000
19,43,1,10780.2500000000000000
19,43,3,10821.0000000000000000
19,43,5,10301.7500000000000000
19,43,6,14655.666666666667
19,43,8,12076.823529411765
19,43,10,10305.3333333333333333
19,43,11,18108.571428571429
19,43,12,8751.0000000000000000
19,43,14,9973.5000000000000000
19,43,15,11840.7500000000000000
19,43,23,3367.5000000000000000
19,43,24,8991.1538461538461538
19,43,25,10751.0000000000000000
19,43,26,13764.125000000000
19,43,31,8537.2500000000000000
19,43,33,19791.111111111111
19,43,35,14261.444444444444
19,43,37,13769.750000000000
19,43,39,12506.000000000000
19,43,40,13695.000000000000
19,47,2,5118.0000000000000000
19,48,54,6951.0000000000000000
19,48,56,3433.0000000000000000
19,48,58,9402.4166666666666667
19,48,59,3292.0000000000000000
19,49,0,10277.0000000000000000
19,49,1,14803.875000000000
19,49,7,14470.500000000000
19,49,10,26686.000000000000
19,49,11,20091.000000000000
19,49,21,3691.0000000000000000
19,49,22,8155.0000000000000000
19,49,23,16555.181818181818
19,49,24,3348.0000000000000000
19,49,25,16269.875000000000
19,49,26,15848.500000000000
19,49,29,16668.500000000000
19,49,30,15028.250000000000
19,49,31,22999.875000000000
19,49,32,14734.083333333333
19,49,35,22447.500000000000
19,49,36,15578.000000000000
19,49,39,17626.250000000000
19,49,41,20711.250000000000
19,49,43,16976.937500000000
19,49,47,11968.0000000000000000
19,49,54,13458.125000000000
19,49,55,12559.000000000000
19,49,56,18347.750000000000
19,49,57,14620.500000000000
19,50,0,23275.750000000000
19,50,2,10016.7500000000000000
19,50,3,28256.250000000000
19,50,4,13031.500000000000
19,50,6,19709.500000000000
19,50,7,22084.375000000000
19,50,8,14460.062500000000
19,50,9,20490.000000000000
19,50,11,13978.000000000000
19,50,12,14834.500000000000
19,50,13,22603.833333333333
19,50,14,12853.250000000000
19,50,18,14137.250000000000
19,50,21,12959.000000000000
19,50,22,10084.5000000000000000
19,50,24,11822.909090909091
19,50,25,53480.000000000000
19,50,27,23069.750000000000
19,50,33,13941.875000000000
19,50,34,12612.500000000000
19,50,36,13657.500000000000
19,50,38,21747.333333333333
19,50,39,14191.000000000000
19,50,43,13695.000000000000
19,50,45,13022.500000000000
19,50,47,14497.250000000000
19,50,49,13374.166666666667
19,50,50,11087.7500000000000000
19,50,59,12045.0000000000000000`
)

View file

@ -1,42 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
In this example we add a new type of series, a `SimpleMovingAverageSeries` that takes another series as a required argument.
InnerSeries only needs to implement `ValueProvider`, so really you could chain `SimpleMovingAverageSeries` together if you wanted.
*/
mainSeries := chart.ContinuousSeries{
Name: "A test series",
XValues: chart.Sequence.Float64(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
YValues: chart.Sequence.Random(100, 100), //generates a []float64 randomly from 0 to 100 with 100 elements.
}
// note we create a SimpleMovingAverage series by assignin the inner series.
// we need to use a reference because `.Render()` needs to modify state within the series.
smaSeries := &chart.SMASeries{
InnerSeries: mainSeries,
} // we can optionally set the `WindowSize` property which alters how the moving average is calculated.
graph := chart.Chart{
Series: []chart.Series{
mainSeries,
smaSeries,
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,62 +0,0 @@
package main
import (
"fmt"
"log"
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
sbc := chart.StackedBarChart{
Height: 512,
XAxis: chart.Style{
Show: true,
},
YAxis: chart.Style{
Show: true,
},
Bars: []chart.StackedBar{
{
Name: "This is a very long string to test word break wrapping.",
Values: []chart.Value{
{Value: 5, Label: "Blue"},
{Value: 5, Label: "Green"},
{Value: 4, Label: "Gray"},
{Value: 3, Label: "Orange"},
{Value: 3, Label: "Test"},
{Value: 2, Label: "??"},
{Value: 1, Label: "!!"},
},
},
{
Name: "Test",
Values: []chart.Value{
{Value: 10, Label: "Blue"},
{Value: 5, Label: "Green"},
{Value: 1, Label: "Gray"},
},
},
{
Name: "Test 2",
Values: []chart.Value{
{Value: 10, Label: "Blue"},
{Value: 6, Label: "Green"},
{Value: 4, Label: "Gray"},
},
},
},
}
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 main() {
http.HandleFunc("/", drawChart)
log.Fatal(http.ListenAndServe(":8080", nil))
}

View file

@ -1,85 +0,0 @@
package main
import (
"net/http"
"time"
"github.com/wcharczuk/go-chart"
"github.com/wcharczuk/go-chart/drawing"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
xv, yv := xvalues(), yvalues()
priceSeries := chart.TimeSeries{
Name: "SPY",
Style: chart.Style{
Show: true,
StrokeColor: chart.GetDefaultColor(0),
},
XValues: xv,
YValues: yv,
}
smaSeries := chart.SMASeries{
Name: "SPY - SMA",
Style: chart.Style{
Show: true,
StrokeColor: drawing.ColorRed,
StrokeDashArray: []float64{5.0, 5.0},
},
InnerSeries: priceSeries,
}
bbSeries := &chart.BollingerBandsSeries{
Name: "SPY - Bol. Bands",
Style: chart.Style{
Show: true,
StrokeColor: drawing.ColorFromHex("efefef"),
FillColor: drawing.ColorFromHex("efefef").WithAlpha(64),
},
InnerSeries: priceSeries,
}
graph := chart.Chart{
XAxis: chart.XAxis{
Style: chart.Style{Show: true},
TickPosition: chart.TickPositionBetweenTicks,
},
YAxis: chart.YAxis{
Style: chart.Style{Show: true},
Range: &chart.ContinuousRange{
Max: 220.0,
Min: 180.0,
},
},
Series: []chart.Series{
bbSeries,
priceSeries,
smaSeries,
},
}
res.Header().Set("Content-Type", "image/svg+xml")
graph.Render(chart.SVG, res)
}
func xvalues() []time.Time {
rawx := []string{"2015-07-17", "2015-07-20", "2015-07-21", "2015-07-22", "2015-07-23", "2015-07-24", "2015-07-27", "2015-07-28", "2015-07-29", "2015-07-30", "2015-07-31", "2015-08-03", "2015-08-04", "2015-08-05", "2015-08-06", "2015-08-07", "2015-08-10", "2015-08-11", "2015-08-12", "2015-08-13", "2015-08-14", "2015-08-17", "2015-08-18", "2015-08-19", "2015-08-20", "2015-08-21", "2015-08-24", "2015-08-25", "2015-08-26", "2015-08-27", "2015-08-28", "2015-08-31", "2015-09-01", "2015-09-02", "2015-09-03", "2015-09-04", "2015-09-08", "2015-09-09", "2015-09-10", "2015-09-11", "2015-09-14", "2015-09-15", "2015-09-16", "2015-09-17", "2015-09-18", "2015-09-21", "2015-09-22", "2015-09-23", "2015-09-24", "2015-09-25", "2015-09-28", "2015-09-29", "2015-09-30", "2015-10-01", "2015-10-02", "2015-10-05", "2015-10-06", "2015-10-07", "2015-10-08", "2015-10-09", "2015-10-12", "2015-10-13", "2015-10-14", "2015-10-15", "2015-10-16", "2015-10-19", "2015-10-20", "2015-10-21", "2015-10-22", "2015-10-23", "2015-10-26", "2015-10-27", "2015-10-28", "2015-10-29", "2015-10-30", "2015-11-02", "2015-11-03", "2015-11-04", "2015-11-05", "2015-11-06", "2015-11-09", "2015-11-10", "2015-11-11", "2015-11-12", "2015-11-13", "2015-11-16", "2015-11-17", "2015-11-18", "2015-11-19", "2015-11-20", "2015-11-23", "2015-11-24", "2015-11-25", "2015-11-27", "2015-11-30", "2015-12-01", "2015-12-02", "2015-12-03", "2015-12-04", "2015-12-07", "2015-12-08", "2015-12-09", "2015-12-10", "2015-12-11", "2015-12-14", "2015-12-15", "2015-12-16", "2015-12-17", "2015-12-18", "2015-12-21", "2015-12-22", "2015-12-23", "2015-12-24", "2015-12-28", "2015-12-29", "2015-12-30", "2015-12-31", "2016-01-04", "2016-01-05", "2016-01-06", "2016-01-07", "2016-01-08", "2016-01-11", "2016-01-12", "2016-01-13", "2016-01-14", "2016-01-15", "2016-01-19", "2016-01-20", "2016-01-21", "2016-01-22", "2016-01-25", "2016-01-26", "2016-01-27", "2016-01-28", "2016-01-29", "2016-02-01", "2016-02-02", "2016-02-03", "2016-02-04", "2016-02-05", "2016-02-08", "2016-02-09", "2016-02-10", "2016-02-11", "2016-02-12", "2016-02-16", "2016-02-17", "2016-02-18", "2016-02-19", "2016-02-22", "2016-02-23", "2016-02-24", "2016-02-25", "2016-02-26", "2016-02-29", "2016-03-01", "2016-03-02", "2016-03-03", "2016-03-04", "2016-03-07", "2016-03-08", "2016-03-09", "2016-03-10", "2016-03-11", "2016-03-14", "2016-03-15", "2016-03-16", "2016-03-17", "2016-03-18", "2016-03-21", "2016-03-22", "2016-03-23", "2016-03-24", "2016-03-28", "2016-03-29", "2016-03-30", "2016-03-31", "2016-04-01", "2016-04-04", "2016-04-05", "2016-04-06", "2016-04-07", "2016-04-08", "2016-04-11", "2016-04-12", "2016-04-13", "2016-04-14", "2016-04-15", "2016-04-18", "2016-04-19", "2016-04-20", "2016-04-21", "2016-04-22", "2016-04-25", "2016-04-26", "2016-04-27", "2016-04-28", "2016-04-29", "2016-05-02", "2016-05-03", "2016-05-04", "2016-05-05", "2016-05-06", "2016-05-09", "2016-05-10", "2016-05-11", "2016-05-12", "2016-05-13", "2016-05-16", "2016-05-17", "2016-05-18", "2016-05-19", "2016-05-20", "2016-05-23", "2016-05-24", "2016-05-25", "2016-05-26", "2016-05-27", "2016-05-31", "2016-06-01", "2016-06-02", "2016-06-03", "2016-06-06", "2016-06-07", "2016-06-08", "2016-06-09", "2016-06-10", "2016-06-13", "2016-06-14", "2016-06-15", "2016-06-16", "2016-06-17", "2016-06-20", "2016-06-21", "2016-06-22", "2016-06-23", "2016-06-24", "2016-06-27", "2016-06-28", "2016-06-29", "2016-06-30", "2016-07-01", "2016-07-05", "2016-07-06", "2016-07-07", "2016-07-08", "2016-07-11", "2016-07-12", "2016-07-13", "2016-07-14", "2016-07-15"}
var dates []time.Time
for _, ts := range rawx {
parsed, _ := time.Parse(chart.DefaultDateFormat, ts)
dates = append(dates, parsed)
}
return dates
}
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}
}
func main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,87 +0,0 @@
package main
import (
"net/http"
"time"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
This is an example of using the `TimeSeries` to automatically coerce time.Time values into a continuous xrange.
Note: chart.TimeSeries implements `ValueFormatterProvider` and as a result gives the XAxis the appropariate formatter to use for the ticks.
*/
graph := chart.Chart{
XAxis: chart.XAxis{
Style: chart.Style{
Show: true,
},
},
Series: []chart.Series{
chart.TimeSeries{
XValues: []time.Time{
time.Now().AddDate(0, 0, -10),
time.Now().AddDate(0, 0, -9),
time.Now().AddDate(0, 0, -8),
time.Now().AddDate(0, 0, -7),
time.Now().AddDate(0, 0, -6),
time.Now().AddDate(0, 0, -5),
time.Now().AddDate(0, 0, -4),
time.Now().AddDate(0, 0, -3),
time.Now().AddDate(0, 0, -2),
time.Now().AddDate(0, 0, -1),
time.Now(),
},
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0},
},
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func drawCustomChart(res http.ResponseWriter, req *http.Request) {
/*
This is basically the other timeseries example, except we switch to hour intervals and specify a different formatter from default for the xaxis tick labels.
*/
graph := chart.Chart{
XAxis: chart.XAxis{
Style: chart.Style{
Show: true,
},
ValueFormatter: chart.TimeHourValueFormatter,
},
Series: []chart.Series{
chart.TimeSeries{
XValues: []time.Time{
time.Now().Add(-10 * time.Hour),
time.Now().Add(-9 * time.Hour),
time.Now().Add(-8 * time.Hour),
time.Now().Add(-7 * time.Hour),
time.Now().Add(-6 * time.Hour),
time.Now().Add(-5 * time.Hour),
time.Now().Add(-4 * time.Hour),
time.Now().Add(-3 * time.Hour),
time.Now().Add(-2 * time.Hour),
time.Now().Add(-1 * time.Hour),
time.Now(),
},
YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0},
},
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.HandleFunc("/favico.ico", func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte{})
})
http.HandleFunc("/custom", drawCustomChart)
http.ListenAndServe(":8080", nil)
}

View file

@ -1,53 +0,0 @@
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
/*
In this example we add a second series, and assign it to the secondary y axis, giving that series it's own range.
We also enable all of the axes by setting the `Show` propery of their respective styles to `true`.
*/
graph := chart.Chart{
XAxis: chart.XAxis{
Style: chart.Style{
Show: true, //enables / displays the x-axis
},
},
YAxis: chart.YAxis{
Style: chart.Style{
Show: true, //enables / displays the y-axis
},
},
YAxisSecondary: chart.YAxis{
Style: chart.Style{
Show: true, //enables / displays the secondary y-axis
},
},
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},
},
chart.ContinuousSeries{
YAxis: chart.YAxisSecondary,
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0},
YValues: []float64{50.0, 40.0, 30.0, 20.0, 10.0},
},
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}