This commit is contained in:
Will Charczuk 2017-03-05 00:59:10 -08:00
parent 2c9a9218e5
commit 046daf94fb
6 changed files with 13 additions and 8 deletions

View File

@ -23,7 +23,7 @@ func parseFloat64(str string) float64 {
func readData() ([]time.Time, []float64) {
var xvalues []time.Time
var yvalues []float64
chart.File.ReadByLines("requests.csv", func(line string) {
err := chart.File.ReadByLines("requests.csv", func(line string) {
parts := strings.Split(line, ",")
year := parseInt(parts[0])
month := parseInt(parts[1])
@ -33,6 +33,9 @@ func readData() ([]time.Time, []float64) {
xvalues = append(xvalues, time.Date(year, time.Month(month), day, hour, 0, 0, 0, time.UTC))
yvalues = append(yvalues, elapsedMillis)
})
if err != nil {
fmt.Println(err.Error())
}
return xvalues, yvalues
}

View File

@ -5,7 +5,6 @@ import (
"net/http"
"github.com/wcharczuk/go-chart"
"github.com/wcharczuk/go-chart/drawing"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
@ -17,7 +16,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
Show: true,
StrokeWidth: chart.Disabled,
DotWidth: 3,
DotColor: drawing.ColorRed,
},
XValues: chart.Sequence.Random(32, 1024),
YValues: chart.Sequence.Random(32, 1024),

View File

@ -513,6 +513,7 @@ func (c Chart) styleDefaultsCanvas() Style {
func (c Chart) styleDefaultsSeries(seriesIndex int) Style {
strokeColor := GetDefaultColor(seriesIndex)
return Style{
DotColor: strokeColor,
StrokeColor: strokeColor,
StrokeWidth: DefaultSeriesLineWidth,
Font: c.GetFont(),

View File

@ -52,6 +52,7 @@ func (d draw) LineSeries(r Renderer, canvasBox Box, xrange, yrange Range, style
y = cb - yrange.Translate(vy)
r.LineTo(x, y)
}
r.Stroke()
}
if style.ShouldDrawDot() {

View File

@ -49,7 +49,9 @@ func (lrs LinearRegressionSeries) GetWindow() int {
// GetEndIndex returns the effective window end.
func (lrs LinearRegressionSeries) GetEndIndex() int {
return Math.MinInt(lrs.GetOffset()+(lrs.Len()), (lrs.InnerSeries.Len() - 1))
offset := lrs.GetOffset() + lrs.Len()
innerSeriesLastIndex := lrs.InnerSeries.Len() - 1
return Math.MinInt(offset, innerSeriesLastIndex)
}
// GetOffset returns the data offset.
@ -62,7 +64,7 @@ func (lrs LinearRegressionSeries) GetOffset() int {
// GetValue gets a value at a given index.
func (lrs *LinearRegressionSeries) GetValue(index int) (x, y float64) {
if lrs.InnerSeries == nil {
if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 {
return
}
if lrs.m == 0 && lrs.b == 0 {
@ -78,7 +80,7 @@ func (lrs *LinearRegressionSeries) GetValue(index int) (x, y float64) {
// GetLastValue computes the last moving average value but walking back window size samples,
// and recomputing the last moving average chunk.
func (lrs *LinearRegressionSeries) GetLastValue() (x, y float64) {
if lrs.InnerSeries == nil {
if lrs.InnerSeries == nil || lrs.InnerSeries.Len() == 0 {
return
}
if lrs.m == 0 && lrs.b == 0 {

View File

@ -50,7 +50,7 @@ func (sma SMASeries) GetPeriod(defaults ...int) int {
// GetValue gets a value at a given index.
func (sma SMASeries) GetValue(index int) (x, y float64) {
if sma.InnerSeries == nil {
if sma.InnerSeries == nil || sma.InnerSeries.Len() == 0 {
return
}
px, _ := sma.InnerSeries.GetValue(index)
@ -62,7 +62,7 @@ func (sma SMASeries) GetValue(index int) (x, y float64) {
// GetLastValue computes the last moving average value but walking back window size samples,
// and recomputing the last moving average chunk.
func (sma SMASeries) GetLastValue() (x, y float64) {
if sma.InnerSeries == nil {
if sma.InnerSeries == nil || sma.InnerSeries.Len() == 0 {
return
}
seriesLen := sma.InnerSeries.Len()