2016-08-01 01:54:09 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/wcharczuk/go-chart"
|
2017-05-13 02:12:23 +02:00
|
|
|
"github.com/wcharczuk/go-chart/seq"
|
|
|
|
"github.com/wcharczuk/go-chart/util"
|
2016-08-01 01:54:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func drawChart(res http.ResponseWriter, req *http.Request) {
|
2017-05-13 02:12:23 +02:00
|
|
|
start := util.Date.Date(2016, 7, 01, util.Date.Eastern())
|
|
|
|
end := util.Date.Date(2016, 07, 21, util.Date.Eastern())
|
|
|
|
xv := seq.Time.MarketHours(start, end, util.NYSEOpen(), util.NYSEClose(), util.Date.IsNYSEHoliday)
|
|
|
|
yv := seq.New(seq.NewRandom().WithLen(len(xv)).WithAverage(200).WithScale(10)).Array()
|
2016-08-01 01:54:09 +02:00
|
|
|
|
|
|
|
graph := chart.Chart{
|
|
|
|
XAxis: chart.XAxis{
|
|
|
|
Style: chart.StyleShow(),
|
|
|
|
TickPosition: chart.TickPositionBetweenTicks,
|
|
|
|
ValueFormatter: chart.TimeHourValueFormatter,
|
|
|
|
Range: &chart.MarketHoursRange{
|
2017-05-13 02:12:23 +02:00
|
|
|
MarketOpen: util.NYSEOpen(),
|
|
|
|
MarketClose: util.NYSEClose(),
|
|
|
|
HolidayProvider: util.Date.IsNYSEHoliday,
|
2016-08-01 01:54:09 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
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)
|
|
|
|
}
|