Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

飞书图表类型错误 #102

Open
jakenlfg opened this issue Oct 11, 2024 · 2 comments
Open

飞书图表类型错误 #102

jakenlfg opened this issue Oct 11, 2024 · 2 comments

Comments

@jakenlfg
Copy link

image 飞书log: image
Copy link

🙏, thanks for your issue.

@jakenlfg
Copy link
Author

ChartSpec 类型改成any后能够正常发送表格
发送图表any结构体示例:

type LineChart struct {
	Type string `json:"type"`
	Data struct {
		Values any `json:"values"`
	} `json:"data"`
	Title struct {
		Text string `json:"text"`
	} `json:"title"`
	XField      string `json:"xField"`
	YField      string `json:"yField"`
	SeriesField string `json:"seriesField"`
	InvalidType string `json:"invalidType"`
}

func PriceToLineChart(prices []*dao.Price) any {
	line := &LineChart{
		Type:        "line",
		InvalidType: "link",
		XField:      "timestamp",
		YField:      "amount",
		SeriesField: "amount_type",
	}

	type Amount struct {
		AmountType string  `json:"amount_type"`
		Amount     float64 `json:"amount"`
		Timestamp  string  `json:"timestamp"`
	}
	data := make([]*Amount, 0)
	for _, v := range prices {
		data = append(data, &Amount{
			AmountType: "price_open",
			Amount:     v.PriceOpen,
			Timestamp:  utils.TimestampToDate(v.TimestampClose),
		})

		data = append(data, &Amount{
			AmountType: "price_high",
			Amount:     v.PriceHigh,
			Timestamp:  utils.TimestampToDate(v.TimestampClose),
		})

		data = append(data, &Amount{
			AmountType: "price_low",
			Amount:     v.PriceLow,
			Timestamp:  utils.TimestampToDate(v.TimestampClose),
		})

		data = append(data, &Amount{
			AmountType: "price_close",
			Amount:     v.PriceClose,
			Timestamp:  utils.TimestampToDate(v.TimestampClose),
		})

		data = append(data, &Amount{
			AmountType: "volume",
			Amount:     v.Volume,
			Timestamp:  utils.TimestampToDate(v.TimestampClose),
		})

		data = append(data, &Amount{
			AmountType: "num_trades",
			Amount:     float64(v.NumTrades),
			Timestamp:  utils.TimestampToDate(v.TimestampClose),
		})
	}
	line.Data.Values = data
	return line
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant