From c42d624892de5f338226f59f7a49c2b5927eafce Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Thu, 7 Jul 2016 23:49:31 -0700 Subject: [PATCH] fixing continuous series. --- series.go | 16 ++++++++-------- testserver/main.go | 12 +++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/series.go b/series.go index b9a4228..2851993 100644 --- a/series.go +++ b/series.go @@ -76,8 +76,8 @@ func (ts TimeSeries) GetYFormatter() Formatter { } } -// ContinousSeries represents a line on a chart. -type ContinousSeries struct { +// ContinuousSeries represents a line on a chart. +type ContinuousSeries struct { Name string Style Style @@ -86,27 +86,27 @@ type ContinousSeries struct { } // GetName returns the name of the time series. -func (cs ContinousSeries) GetName() string { +func (cs ContinuousSeries) GetName() string { return cs.Name } // GetStyle returns the line style. -func (cs ContinousSeries) GetStyle() Style { +func (cs ContinuousSeries) GetStyle() Style { return cs.Style } // Len returns the number of elements in the series. -func (cs ContinousSeries) Len() int { +func (cs ContinuousSeries) Len() int { return len(cs.XValues) } // GetValue gets a value at a given index. -func (cs ContinousSeries) GetValue(index int) (interface{}, float64) { +func (cs ContinuousSeries) GetValue(index int) (float64, float64) { return cs.XValues[index], cs.YValues[index] } // GetXFormatter returns the xs value formatter. -func (cs ContinousSeries) GetXFormatter() Formatter { +func (cs ContinuousSeries) GetXFormatter() Formatter { return func(v interface{}) string { if typed, isTyped := v.(float64); isTyped { return fmt.Sprintf("%0.2f", typed) @@ -116,6 +116,6 @@ func (cs ContinousSeries) GetXFormatter() Formatter { } // GetYFormatter returns the y value formatter. -func (cs ContinousSeries) GetYFormatter() Formatter { +func (cs ContinuousSeries) GetYFormatter() Formatter { return cs.GetXFormatter() } diff --git a/testserver/main.go b/testserver/main.go index 2d407bb..bb2748b 100644 --- a/testserver/main.go +++ b/testserver/main.go @@ -3,7 +3,6 @@ package main import ( "bytes" "log" - "time" "github.com/wcharczuk/go-chart" "github.com/wcharczuk/go-web" @@ -15,7 +14,6 @@ func main() { app.SetLogger(web.NewStandardOutputLogger()) app.GET("/", func(rc *web.RequestContext) web.ControllerResult { rc.Response.Header().Set("Content-Type", "image/svg+xml") - now := time.Now() c := chart.Chart{ Title: "A Test Chart", TitleStyle: chart.Style{ @@ -35,14 +33,14 @@ func main() { Show: true, }, Series: []chart.Series{ - chart.TimeSeries{ + chart.ContinuousSeries{ Name: "a", - XValues: []time.Time{now.AddDate(0, 0, -4), now.AddDate(0, 0, -3), now.AddDate(0, 0, -2), now.AddDate(0, 0, -1)}, - YValues: []float64{2.5, 5.0, 2.0, 3.0}, + XValues: []float64{1.0, 2.0, 3.0, 4.0}, + YValues: []float64{2.5, 5.0, 2.0, 3.3}, }, - chart.TimeSeries{ + chart.ContinuousSeries{ Name: "b", - XValues: []time.Time{now.AddDate(0, 0, -4), now.AddDate(0, 0, -3), now.AddDate(0, 0, -2), now.AddDate(0, 0, -1)}, + XValues: []float64{3.0, 4.0, 5.0, 6.0}, YValues: []float64{6.0, 5.0, 4.0, 1.0}, }, },