mostly working
This commit is contained in:
parent
26eaa1d898
commit
5f42a580a9
47 changed files with 914 additions and 637 deletions
|
|
@ -27,7 +27,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
},
|
||||
Series: []chart.Series{
|
||||
chart.ContinuousSeries{
|
||||
XValues: seq.Range(1.0, 100.0),
|
||||
XValues: SeqRange(1.0, 100.0),
|
||||
YValues: seq.RandomValuesWithMax(100, 512),
|
||||
},
|
||||
},
|
||||
|
|
@ -50,7 +50,7 @@ func drawChartDefault(res http.ResponseWriter, req *http.Request) {
|
|||
},
|
||||
Series: []chart.Series{
|
||||
chart.ContinuousSeries{
|
||||
XValues: seq.Range(1.0, 100.0),
|
||||
XValues: SeqRange(1.0, 100.0),
|
||||
YValues: seq.RandomValuesWithMax(100, 512),
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
|
||||
mainSeries := chart.ContinuousSeries{
|
||||
Name: "A test series",
|
||||
XValues: seq.Range(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||
XValues: SeqRange(1.0, 100.0), //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.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
mainSeries := chart.ContinuousSeries{
|
||||
Name: "A test series",
|
||||
XValues: seq.Range(1.0, 100.0),
|
||||
XValues: SeqRange(1.0, 100.0),
|
||||
YValues: seq.New(seq.NewRandom().WithLen(100).WithMax(150).WithMin(50)).Array(),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
|
||||
mainSeries := chart.ContinuousSeries{
|
||||
Name: "A test series",
|
||||
XValues: seq.Range(1.0, 100.0), //generates a []float64 from 1.0 to 100.0 in 1.0 step increments, or 100 elements.
|
||||
XValues: SeqRange(1.0, 100.0), //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.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
chart "github.com/wcharczuk/go-chart"
|
||||
|
|
@ -24,7 +23,7 @@ func readData() ([]time.Time, []float64) {
|
|||
var xvalues []time.Time
|
||||
var yvalues []float64
|
||||
err := chart.ReadLines("requests.csv", func(line string) error {
|
||||
parts := strings.Split(line, ",")
|
||||
parts := chart.SplitCSV(line)
|
||||
year := parseInt(parts[0])
|
||||
month := parseInt(parts[1])
|
||||
day := parseInt(parts[2])
|
||||
|
|
@ -51,84 +50,84 @@ func releases() []chart.GridLine {
|
|||
}
|
||||
}
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
xvalues, yvalues := readData()
|
||||
mainSeries := chart.TimeSeries{
|
||||
Name: "Prod Request Timings",
|
||||
Style: chart.Style{
|
||||
Show: true,
|
||||
StrokeColor: chart.ColorBlue,
|
||||
FillColor: chart.ColorBlue.WithAlpha(100),
|
||||
},
|
||||
XValues: xvalues,
|
||||
YValues: yvalues,
|
||||
}
|
||||
|
||||
linreg := &chart.LinearRegressionSeries{
|
||||
Name: "Linear Regression",
|
||||
Style: chart.Style{
|
||||
Show: true,
|
||||
StrokeColor: chart.ColorAlternateBlue,
|
||||
StrokeDashArray: []float64{5.0, 5.0},
|
||||
},
|
||||
InnerSeries: mainSeries,
|
||||
}
|
||||
|
||||
sma := &chart.SMASeries{
|
||||
Name: "SMA",
|
||||
Style: chart.Style{
|
||||
Show: true,
|
||||
StrokeColor: chart.ColorRed,
|
||||
StrokeDashArray: []float64{5.0, 5.0},
|
||||
},
|
||||
InnerSeries: mainSeries,
|
||||
}
|
||||
|
||||
graph := chart.Chart{
|
||||
Width: 1280,
|
||||
Height: 720,
|
||||
Background: chart.Style{
|
||||
Padding: chart.Box{
|
||||
Top: 50,
|
||||
func drawChart(log chart.Logger) http.HandlerFunc {
|
||||
return func(res http.ResponseWriter, req *http.Request) {
|
||||
xvalues, yvalues := readData()
|
||||
mainSeries := chart.TimeSeries{
|
||||
Name: "Prod Request Timings",
|
||||
Style: chart.Style{
|
||||
StrokeColor: chart.ColorBlue,
|
||||
FillColor: chart.ColorBlue.WithAlpha(100),
|
||||
},
|
||||
},
|
||||
YAxis: chart.YAxis{
|
||||
Name: "Elapsed Millis",
|
||||
NameStyle: chart.StyleShow(),
|
||||
Style: chart.StyleShow(),
|
||||
TickStyle: chart.Style{
|
||||
TextRotationDegrees: 45.0,
|
||||
XValues: xvalues,
|
||||
YValues: yvalues,
|
||||
}
|
||||
|
||||
linreg := &chart.LinearRegressionSeries{
|
||||
Name: "Linear Regression",
|
||||
Style: chart.Style{
|
||||
StrokeColor: chart.ColorAlternateBlue,
|
||||
StrokeDashArray: []float64{5.0, 5.0},
|
||||
},
|
||||
ValueFormatter: func(v interface{}) string {
|
||||
return fmt.Sprintf("%d ms", int(v.(float64)))
|
||||
InnerSeries: mainSeries,
|
||||
}
|
||||
|
||||
sma := &chart.SMASeries{
|
||||
Name: "SMA",
|
||||
Style: chart.Style{
|
||||
StrokeColor: chart.ColorRed,
|
||||
StrokeDashArray: []float64{5.0, 5.0},
|
||||
},
|
||||
},
|
||||
XAxis: chart.XAxis{
|
||||
Style: chart.StyleShow(),
|
||||
ValueFormatter: chart.TimeHourValueFormatter,
|
||||
GridMajorStyle: chart.Style{
|
||||
Show: true,
|
||||
StrokeColor: chart.ColorAlternateGray,
|
||||
StrokeWidth: 1.0,
|
||||
InnerSeries: mainSeries,
|
||||
}
|
||||
|
||||
graph := chart.Chart{
|
||||
Log: log,
|
||||
Width: 1280,
|
||||
Height: 720,
|
||||
Background: chart.Style{
|
||||
Padding: chart.Box{
|
||||
Top: 50,
|
||||
},
|
||||
},
|
||||
GridLines: releases(),
|
||||
},
|
||||
Series: []chart.Series{
|
||||
mainSeries,
|
||||
linreg,
|
||||
chart.LastValueAnnotation(linreg),
|
||||
sma,
|
||||
chart.LastValueAnnotation(sma),
|
||||
},
|
||||
YAxis: chart.YAxis{
|
||||
Name: "Elapsed Millis",
|
||||
TickStyle: chart.Style{
|
||||
TextRotationDegrees: 45.0,
|
||||
},
|
||||
ValueFormatter: func(v interface{}) string {
|
||||
return fmt.Sprintf("%d ms", int(v.(float64)))
|
||||
},
|
||||
},
|
||||
XAxis: chart.XAxis{
|
||||
ValueFormatter: chart.TimeHourValueFormatter,
|
||||
GridMajorStyle: chart.Style{
|
||||
StrokeColor: chart.ColorAlternateGray,
|
||||
StrokeWidth: 1.0,
|
||||
},
|
||||
GridLines: releases(),
|
||||
},
|
||||
Series: []chart.Series{
|
||||
mainSeries,
|
||||
linreg,
|
||||
chart.LastValueAnnotation(linreg),
|
||||
sma,
|
||||
chart.LastValueAnnotation(sma),
|
||||
},
|
||||
}
|
||||
|
||||
graph.Elements = []chart.Renderable{chart.LegendThin(&graph)}
|
||||
|
||||
res.Header().Set("Content-Type", chart.ContentTypePNG)
|
||||
if err := graph.Render(chart.PNG, res); err != nil {
|
||||
log.Err(err)
|
||||
}
|
||||
}
|
||||
|
||||
graph.Elements = []chart.Renderable{chart.LegendThin(&graph)}
|
||||
|
||||
res.Header().Set("Content-Type", chart.ContentTypePNG)
|
||||
graph.Render(chart.PNG, res)
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", drawChart)
|
||||
log := chart.NewLogger()
|
||||
log.Infof("listening on :8080")
|
||||
http.HandleFunc("/", drawChart(log))
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,8 @@ import (
|
|||
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
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) {
|
||||
|
|
@ -26,8 +25,8 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
DotWidth: 5,
|
||||
DotColorProvider: viridisByY,
|
||||
},
|
||||
XValues: seq.Range(0, 127),
|
||||
YValues: seq.New(seq.NewRandom().WithLen(128).WithMax(1024)).Array(),
|
||||
XValues: chart.SeqRange(0, 127),
|
||||
YValues: chart.NewSeq(chart.NewSeqRandom().WithLen(128).WithMax(1024)).Values(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -51,8 +50,8 @@ func unit(res http.ResponseWriter, req *http.Request) {
|
|||
},
|
||||
Series: []chart.Series{
|
||||
chart.ContinuousSeries{
|
||||
XValues: seq.RangeWithStep(0, 4, 1),
|
||||
YValues: seq.RangeWithStep(0, 4, 1),
|
||||
XValues: chart.SeqRangeWithStep(0, 4, 1),
|
||||
YValues: chart.SeqRangeWithStep(0, 4, 1),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,16 +3,15 @@ package main
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/seq"
|
||||
chart "github.com/wcharczuk/go-chart"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
|
||||
mainSeries := chart.ContinuousSeries{
|
||||
Name: "A test series",
|
||||
XValues: seq.Range(1.0, 100.0), //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.
|
||||
XValues: chart.SeqRange(1.0, 100.0), //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.
|
||||
}
|
||||
|
||||
// note we create a SimpleMovingAverage series by assignin the inner series.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
chart "github.com/wcharczuk/go-chart"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
chart "github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/drawing"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
chart "github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/drawing"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
chart "github.com/wcharczuk/go-chart"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
util "github.com/wcharczuk/go-chart/util"
|
||||
chart "github.com/wcharczuk/go-chart"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
|
|
@ -22,7 +21,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
|||
TickPosition: chart.TickPositionBetweenTicks,
|
||||
ValueFormatter: func(v interface{}) string {
|
||||
typed := v.(float64)
|
||||
typedDate := util.Time.FromFloat64(typed)
|
||||
typedDate := chart.TimeFromFloat64(typed)
|
||||
return fmt.Sprintf("%d-%d\n%d", typedDate.Month(), typedDate.Day(), typedDate.Year())
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
chart "github.com/wcharczuk/go-chart"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue