fixing continuous series.

This commit is contained in:
Will Charczuk 2016-07-07 23:49:31 -07:00
parent 6ac3c4c751
commit c42d624892
2 changed files with 13 additions and 15 deletions

View file

@ -76,8 +76,8 @@ func (ts TimeSeries) GetYFormatter() Formatter {
} }
} }
// ContinousSeries represents a line on a chart. // ContinuousSeries represents a line on a chart.
type ContinousSeries struct { type ContinuousSeries struct {
Name string Name string
Style Style Style Style
@ -86,27 +86,27 @@ type ContinousSeries struct {
} }
// GetName returns the name of the time series. // GetName returns the name of the time series.
func (cs ContinousSeries) GetName() string { func (cs ContinuousSeries) GetName() string {
return cs.Name return cs.Name
} }
// GetStyle returns the line style. // GetStyle returns the line style.
func (cs ContinousSeries) GetStyle() Style { func (cs ContinuousSeries) GetStyle() Style {
return cs.Style return cs.Style
} }
// Len returns the number of elements in the series. // Len returns the number of elements in the series.
func (cs ContinousSeries) Len() int { func (cs ContinuousSeries) Len() int {
return len(cs.XValues) return len(cs.XValues)
} }
// GetValue gets a value at a given index. // 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] return cs.XValues[index], cs.YValues[index]
} }
// GetXFormatter returns the xs value formatter. // GetXFormatter returns the xs value formatter.
func (cs ContinousSeries) GetXFormatter() Formatter { func (cs ContinuousSeries) GetXFormatter() Formatter {
return func(v interface{}) string { return func(v interface{}) string {
if typed, isTyped := v.(float64); isTyped { if typed, isTyped := v.(float64); isTyped {
return fmt.Sprintf("%0.2f", typed) return fmt.Sprintf("%0.2f", typed)
@ -116,6 +116,6 @@ func (cs ContinousSeries) GetXFormatter() Formatter {
} }
// GetYFormatter returns the y value formatter. // GetYFormatter returns the y value formatter.
func (cs ContinousSeries) GetYFormatter() Formatter { func (cs ContinuousSeries) GetYFormatter() Formatter {
return cs.GetXFormatter() return cs.GetXFormatter()
} }

View file

@ -3,7 +3,6 @@ package main
import ( import (
"bytes" "bytes"
"log" "log"
"time"
"github.com/wcharczuk/go-chart" "github.com/wcharczuk/go-chart"
"github.com/wcharczuk/go-web" "github.com/wcharczuk/go-web"
@ -15,7 +14,6 @@ func main() {
app.SetLogger(web.NewStandardOutputLogger()) app.SetLogger(web.NewStandardOutputLogger())
app.GET("/", func(rc *web.RequestContext) web.ControllerResult { app.GET("/", func(rc *web.RequestContext) web.ControllerResult {
rc.Response.Header().Set("Content-Type", "image/svg+xml") rc.Response.Header().Set("Content-Type", "image/svg+xml")
now := time.Now()
c := chart.Chart{ c := chart.Chart{
Title: "A Test Chart", Title: "A Test Chart",
TitleStyle: chart.Style{ TitleStyle: chart.Style{
@ -35,14 +33,14 @@ func main() {
Show: true, Show: true,
}, },
Series: []chart.Series{ Series: []chart.Series{
chart.TimeSeries{ chart.ContinuousSeries{
Name: "a", 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)}, XValues: []float64{1.0, 2.0, 3.0, 4.0},
YValues: []float64{2.5, 5.0, 2.0, 3.0}, YValues: []float64{2.5, 5.0, 2.0, 3.3},
}, },
chart.TimeSeries{ chart.ContinuousSeries{
Name: "b", 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}, YValues: []float64{6.0, 5.0, 4.0, 1.0},
}, },
}, },