基于 Echarts + Golang gin 实现的动态实时可视化数据大屏展示范例二

参考这个案例https://blog.csdn.net/lildkdkdkjf/article/details/106783264,手痒,改成Golang版:)

先看效果图:

实现原理:

前端Echarts实现:https://echarts.apache.org/zh/index.html,前端就不贴了,在文章最后的地址里下载。

后台Golang实现,用https://github.com/gin-gonic/gin启动一个http服务,加载页面。再用https://github.com/zserge/lorca调用本机的Chrome浏览器访问该页面。用https://github.com/astaxie/beego/orm访问数据库,模拟获取数据。

关键代码:

main.go

package main

import (
	"fmt"
	"time"

	"github.com/go-vgo/robotgo"
	"github.com/zserge/lorca"
)

var ui lorca.UI
var loadFinished bool

//模拟刷新数据
func ChangeData() {
	for 1 == 1 {
		time.Sleep(5000)
		change_chart_1()
		change_chart_2()
		change_chart_map()
		change_chart_3()
		//change_chart_4()
		change_chart_5()
		change_table(table_1_FILENAME)
		change_table(table_2_FILENAME)
		change_table(table_3_FILENAME)
		if loadFinished == true {
			ui.Eval(`
		            async_data_chart_1();
					async_data_chart_2();
					async_data_chart_map();
					async_data_chart_3();
					//async_data_chart_4();
					async_data_chart_5();
					async_data_table_1();
					async_data_table_2();
					async_data_table_3();
			`)
		}
	}
}

func main() {
	go init_http_server()
	ui, _ = lorca.New(fmt.Sprintf("http://%s:%d", ip, port), "", 1024, 768)

	//记得在html里加<body onload=loadFinished()>
	ui.Bind("loadFinished", func() { loadFinished = true })

	//需要先安装mingw64,http://www.mingw-w64.org/doku.php/download
	robotgo.KeyTap(`f11`) //全屏

	defer ui.Close()

	go ChangeData()
	<-ui.Done()
}

httpserver.go

package main

import (
	"fmt"

	"github.com/gin-gonic/gin"
)

var ip string = "localhost" //监听IP,配置项
var port int = 8808         //监听端口,配置项

func init_http_server() {
	router := gin.Default()
	router.Static("/css", "./css")
	router.Static("/images", "./images")
	router.Static("/img", "./img")
	router.Static("/js", "./js")
	router.Static("/json", "./json")
	router.Static("/page", "./page")
	router.Static("/picture", "./picture")
	router.LoadHTMLFiles("./index.html")
	router.GET("/", func(c *gin.Context) {
		c.HTML(200, "index.html", nil)
	})
	router.Run(fmt.Sprintf(":%d", port))
}

示例程序

链接:https://pan.baidu.com/s/1WoBGL42yemaJLu_Plw5blQ 
提取码:gkrm 

包含完整的前端源码。运行GoDataV.exe前记得安装最新的Chrome浏览器,按F11放大缩小。

需要linux或Mac版的请找作者编译一个。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昵称6550523

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值