go-chart/time_series.go

55 lines
1.2 KiB
Go
Raw Permalink Normal View History

2016-07-09 23:14:11 -04:00
package chart
2016-07-10 04:11:47 -04:00
import "time"
2016-07-09 23:14:11 -04:00
// TimeSeries is a line on a chart.
type TimeSeries struct {
2016-07-10 04:11:47 -04:00
Name string
Style Style
YAxis YAxisType
2016-07-09 23:14:11 -04:00
XValues []time.Time
YValues []float64
}
// GetName returns the name of the time series.
func (ts TimeSeries) GetName() string {
return ts.Name
}
// GetStyle returns the line style.
func (ts TimeSeries) GetStyle() Style {
return ts.Style
}
// Len returns the number of elements in the series.
func (ts TimeSeries) Len() int {
return len(ts.XValues)
}
// GetValue gets a value at a given index.
func (ts TimeSeries) GetValue(index int) (x float64, y float64) {
2016-07-13 14:50:22 -04:00
x = TimeToFloat64(ts.XValues[index])
2016-07-09 23:14:11 -04:00
y = ts.YValues[index]
return
}
2016-07-10 13:43:04 -04:00
// GetValueFormatters returns value formatter defaults for the series.
func (ts TimeSeries) GetValueFormatters() (x, y ValueFormatter) {
x = TimeValueFormatter
y = FloatValueFormatter
return
}
// GetYAxis returns which YAxis the series draws on.
func (ts TimeSeries) GetYAxis() YAxisType {
return ts.YAxis
}
2016-07-10 04:11:47 -04:00
// Render renders the series.
func (ts TimeSeries) Render(r Renderer, canvasBox Box, xrange, yrange Range, defaults Style) {
style := ts.Style.WithDefaultsFrom(defaults)
DrawLineSeries(r, canvasBox, xrange, yrange, style, ts)
2016-07-09 23:14:11 -04:00
}