Skip to content

Commit

Permalink
修复图表年数不够时时间轴错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Jul 17, 2021
1 parent 3530d0d commit 2dcacfb
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions routes/stock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package routes

import (
"fmt"
"math"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -120,11 +121,6 @@ func StockChecker(c *gin.Context) {
finaReportNames := []string{}
finaAppointPublishDates := []string{}
lines := [][]gin.H{}
yearLabels := []string{}
year := time.Now().Year()
for i := param.CheckerOptions.CheckYears; i > 0; i-- {
yearLabels = append(yearLabels, fmt.Sprint(year-i))
}

type dataset struct {
Label string `json:"label"`
Expand All @@ -143,6 +139,20 @@ func StockChecker(c *gin.Context) {
finaReportNames = append(finaReportNames, finaReportName)

finaAppointPublishDates = append(finaAppointPublishDates, strings.Split(stock.FinaAppointPublishDate, " ")[0])

roeList := goutils.ReversedFloat64Slice(
stock.HistoricalFinaMainData.ValueList(
c,
eastmoney.ValueListTypeROE,
param.CheckerOptions.CheckYears,
eastmoney.FinaReportTypeYear,
))
yearLabels := []string{}
year := time.Now().Year()
yearcount := int(math.Min(float64(param.CheckerOptions.CheckYears), float64(len(roeList))))
for i := yearcount; i > 0; i-- {
yearLabels = append(yearLabels, fmt.Sprint(year-i))
}
line0 := gin.H{
"title": "",
"xLable": "年",
Expand All @@ -152,12 +162,7 @@ func StockChecker(c *gin.Context) {
"datasets": []dataset{
{
Label: "ROE",
Data: goutils.ReversedFloat64Slice(stock.HistoricalFinaMainData.ValueList(
c,
eastmoney.ValueListTypeROE,
param.CheckerOptions.CheckYears,
eastmoney.FinaReportTypeYear,
)),
Data: roeList,
},
{
Label: "EPS",
Expand Down

0 comments on commit 2dcacfb

Please sign in to comment.