go-chart/_examples/market_hours/main.go

45 lines
1.1 KiB
Go
Raw Permalink Normal View History

2016-07-31 19:54:09 -04:00
package main
import (
"net/http"
"github.com/wcharczuk/go-chart"
)
func drawChart(res http.ResponseWriter, req *http.Request) {
2016-08-05 19:55:55 -04:00
start := chart.Date.Date(2016, 7, 01, chart.Date.Eastern())
2016-08-01 03:50:32 -04:00
end := chart.Date.Date(2016, 07, 21, chart.Date.Eastern())
2016-07-31 19:54:09 -04:00
xv := chart.Sequence.MarketHours(start, end, chart.NYSEOpen, chart.NYSEClose, chart.Date.IsNYSEHoliday)
yv := chart.Sequence.RandomWithAverage(len(xv), 200, 10)
graph := chart.Chart{
XAxis: chart.XAxis{
Style: chart.StyleShow(),
TickPosition: chart.TickPositionBetweenTicks,
ValueFormatter: chart.TimeHourValueFormatter,
Range: &chart.MarketHoursRange{
MarketOpen: chart.NYSEOpen,
MarketClose: chart.NYSEClose,
HolidayProvider: chart.Date.IsNYSEHoliday,
},
},
YAxis: chart.YAxis{
Style: chart.StyleShow(),
},
Series: []chart.Series{
chart.TimeSeries{
XValues: xv,
YValues: yv,
},
},
}
res.Header().Set("Content-Type", "image/png")
graph.Render(chart.PNG, res)
}
func main() {
http.HandleFunc("/", drawChart)
http.ListenAndServe(":8080", nil)
}