add echart barchart

This commit is contained in:
2024-07-05 10:55:47 +07:00
parent eb7343117b
commit f2d8207f25
13 changed files with 770 additions and 118 deletions

28
utils/chartcolor.utils.go Normal file
View File

@@ -0,0 +1,28 @@
package utils
import (
"fmt"
"math"
)
// InterpolateColor calculates a color between two given colors based on progress (0 to 1)
func InterpolateColor(start, end string, progress float64) string {
r1, g1, b1 := HexToRGB(start)
r2, g2, b2 := HexToRGB(end)
r := int(math.Round(float64(r1)*(1-progress) + float64(r2)*progress))
g := int(math.Round(float64(g1)*(1-progress) + float64(g2)*progress))
b := int(math.Round(float64(b1)*(1-progress) + float64(b2)*progress))
return fmt.Sprintf("#%02x%02x%02x", r, g, b)
}
// Helper function to convert hex to RGB
func HexToRGB(hex string) (int, int, int) {
var r, g, b int
_, err := fmt.Sscanf(hex, "#%02x%02x%02x", &r, &g, &b)
if err != nil {
return 0, 0, 0
}
return r, g, b
}