additions
This commit is contained in:
parent
602ff901f7
commit
6d57cf4533
3 changed files with 43 additions and 5 deletions
|
@ -14,7 +14,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
priceSeries := chart.TimeSeries{
|
priceSeries := chart.TimeSeries{
|
||||||
Name: "SPY",
|
Name: "SPY",
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
|
||||||
StrokeColor: chart.GetDefaultColor(0),
|
StrokeColor: chart.GetDefaultColor(0),
|
||||||
},
|
},
|
||||||
XValues: xv,
|
XValues: xv,
|
||||||
|
@ -24,7 +23,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
smaSeries := chart.SMASeries{
|
smaSeries := chart.SMASeries{
|
||||||
Name: "SPY - SMA",
|
Name: "SPY - SMA",
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
|
||||||
StrokeColor: drawing.ColorRed,
|
StrokeColor: drawing.ColorRed,
|
||||||
StrokeDashArray: []float64{5.0, 5.0},
|
StrokeDashArray: []float64{5.0, 5.0},
|
||||||
},
|
},
|
||||||
|
@ -34,7 +32,6 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
bbSeries := &chart.BollingerBandsSeries{
|
bbSeries := &chart.BollingerBandsSeries{
|
||||||
Name: "SPY - Bol. Bands",
|
Name: "SPY - Bol. Bands",
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
|
||||||
StrokeColor: drawing.ColorFromHex("efefef"),
|
StrokeColor: drawing.ColorFromHex("efefef"),
|
||||||
FillColor: drawing.ColorFromHex("efefef").WithAlpha(64),
|
FillColor: drawing.ColorFromHex("efefef").WithAlpha(64),
|
||||||
},
|
},
|
||||||
|
@ -43,11 +40,9 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
graph := chart.Chart{
|
graph := chart.Chart{
|
||||||
XAxis: chart.XAxis{
|
XAxis: chart.XAxis{
|
||||||
Style: chart.StyleShow(),
|
|
||||||
TickPosition: chart.TickPositionBetweenTicks,
|
TickPosition: chart.TickPositionBetweenTicks,
|
||||||
},
|
},
|
||||||
YAxis: chart.YAxis{
|
YAxis: chart.YAxis{
|
||||||
Style: chart.StyleShow(),
|
|
||||||
Range: &chart.ContinuousRange{
|
Range: &chart.ContinuousRange{
|
||||||
Max: 220.0,
|
Max: 220.0,
|
||||||
Min: 180.0,
|
Min: 180.0,
|
||||||
|
|
36
bounded_last_values_annotation_series.go
Normal file
36
bounded_last_values_annotation_series.go
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
package chart
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// BoundedLastValuesAnnotationSeries returns a last value annotation series for a bounded values provider.
|
||||||
|
func BoundedLastValuesAnnotationSeries(innerSeries FullBoundedValuesProvider, vfs ...ValueFormatter) AnnotationSeries {
|
||||||
|
lvx, lvy1, lvy2 := innerSeries.GetBoundedLastValues()
|
||||||
|
|
||||||
|
var vf ValueFormatter
|
||||||
|
if len(vfs) > 0 {
|
||||||
|
vf = vfs[0]
|
||||||
|
} else if typed, isTyped := innerSeries.(ValueFormatterProvider); isTyped {
|
||||||
|
_, vf = typed.GetValueFormatters()
|
||||||
|
} else {
|
||||||
|
vf = FloatValueFormatter
|
||||||
|
}
|
||||||
|
|
||||||
|
label1 := vf(lvy1)
|
||||||
|
label2 := vf(lvy2)
|
||||||
|
|
||||||
|
var seriesName string
|
||||||
|
var seriesStyle Style
|
||||||
|
if typed, isTyped := innerSeries.(Series); isTyped {
|
||||||
|
seriesName = fmt.Sprintf("%s - Last Values", typed.GetName())
|
||||||
|
seriesStyle = typed.GetStyle()
|
||||||
|
}
|
||||||
|
|
||||||
|
return AnnotationSeries{
|
||||||
|
Name: seriesName,
|
||||||
|
Style: seriesStyle,
|
||||||
|
Annotations: []Value2{
|
||||||
|
{XValue: lvx, YValue: lvy1, Label: label1},
|
||||||
|
{XValue: lvx, YValue: lvy2, Label: label2},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
|
@ -96,3 +96,10 @@ func FloatValueFormatterWithFormat(v interface{}, floatFormat string) string {
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KValueFormatter is a formatter for K values.
|
||||||
|
func KValueFormatter(k float64, vf ValueFormatter) ValueFormatter {
|
||||||
|
return func(v interface{}) string {
|
||||||
|
return fmt.Sprintf("%0.0fσ %s", k, vf(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue