diff --git a/_examples/request_timings/main.go b/_examples/request_timings/main.go index bcaf968..aed7493 100644 --- a/_examples/request_timings/main.go +++ b/_examples/request_timings/main.go @@ -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 } diff --git a/_examples/scatter/main.go b/_examples/scatter/main.go index 6e94e6d..b7d15af 100644 --- a/_examples/scatter/main.go +++ b/_examples/scatter/main.go @@ -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), diff --git a/chart.go b/chart.go index da11756..47597ed 100644 --- a/chart.go +++ b/chart.go @@ -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(), diff --git a/draw.go b/draw.go index be24733..6b8e3f7 100644 --- a/draw.go +++ b/draw.go @@ -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() { diff --git a/linear_regression_series.go b/linear_regression_series.go index bcd045b..142ea55 100644 --- a/linear_regression_series.go +++ b/linear_regression_series.go @@ -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 { diff --git a/sma_series.go b/sma_series.go index d9f7f13..f68c60d 100644 --- a/sma_series.go +++ b/sma_series.go @@ -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()