add go-charts
continuous-integration/drone/push Build is passing Details

master
dustoair 3 years ago
parent 784ce8fb13
commit c84b9d0c44

@ -5,8 +5,10 @@ go 1.19
require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/gorm v1.9.16 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
@ -21,9 +23,12 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.12.0 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
github.com/vicanso/go-charts/v2 v2.2.0 // indirect
github.com/wcharczuk/go-chart/v2 v2.1.0 // indirect
golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

@ -0,0 +1,110 @@
package goCharts
/*
*
@author: sre
@date: 2022/9/17 0017
@desc: todo
*
*/
import (
"github.com/vicanso/go-charts/v2"
)
func Draw() {
values := [][]float64{
{
120,
132,
101,
// 134,
//charts.GetNullValue(),
134,
90,
230,
210,
},
{
220,
182,
191,
234,
290,
330,
310,
},
{
150,
232,
201,
154,
190,
330,
410,
},
{
320,
332,
301,
334,
390,
330,
320,
},
{
820,
932,
901,
934,
1290,
1330,
1320,
},
}
p, err := charts.LineRender(
values,
//charts.SVGTypeOption(),
charts.ThemeOptionFunc(charts.ThemeGrafana),
charts.WidthOptionFunc(1080),
charts.HeightOptionFunc(1920),
charts.TitleTextOptionFunc("Line"),
charts.XAxisDataOptionFunc([]string{
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
}),
charts.LegendLabelsOptionFunc([]string{
"Email",
"Union Ads",
"Video Ads",
"Direct",
"Search Engine",
}, "50"),
func(opt *charts.ChartOption) {
opt.Legend.Padding = charts.Box{
Top: 5,
Bottom: 10,
}
opt.SymbolShow = charts.FalseFlag()
opt.LineStrokeWidth = 1
},
)
if err != nil {
panic(err)
}
buf, err := p.Bytes()
if err != nil {
panic(err)
}
err = writeFile(buf)
if err != nil {
panic(err)
}
}

@ -0,0 +1,28 @@
package goCharts
import (
"os"
"path/filepath"
)
/*
*
@author: sre
@date: 2022/9/17 0017
@desc: todo
*
*/
func writeFile(buf []byte) error {
tmpPath := "./tmp"
err := os.MkdirAll(tmpPath, 0700)
if err != nil {
return err
}
file := filepath.Join(tmpPath, "line-chart.png")
err = os.WriteFile(file, buf, 0600)
if err != nil {
return err
}
return nil
}

@ -2,12 +2,21 @@ package handle
import (
"WechatGateWay/global"
"WechatGateWay/goCharts"
"WechatGateWay/third_part"
"WechatGateWay/utils"
"net/http"
)
func replyImage(msgContent MsgContent, timestamp, nonce string, w http.ResponseWriter) {
//third_part.SendPicMid(msgContent.FromUsername, utils.RandMapValue(global.ImageMap))
goCharts.Draw()
filename := "tmp/line-chart.png"
go RecordWechatLog(msgContent.FromUsername, msgContent.ToUsername, msgContent.CreateTime, msgContent.MsgType, filename)
third_part.SendPicFile(msgContent.FromUsername, filename)
}
func replyImageEmoj(msgContent MsgContent, timestamp, nonce string, w http.ResponseWriter) {
//third_part.SendPicMid(msgContent.FromUsername, utils.RandMapValue(global.ImageMap))
filename := global.WechatImagePath + "/" + utils.RandomFile(global.WechatImagePath)
go RecordWechatLog(msgContent.FromUsername, msgContent.ToUsername, msgContent.CreateTime, msgContent.MsgType, filename)

Loading…
Cancel
Save