Giter Site home page Giter Site logo

statsview's Introduction

go-echarts

🎨 The adorable charts library for Golang.

Build Status Go Report Card Contributions welcome MIT License GoDoc echartsVersion handbook

If a language can be used to build web scrapers, it definitely needs to provide a graceful data visualization library. --- by dongdong.

In the Golang ecosystem, there are not many choices for data visualization libraries.
The development of go-echarts aims to provide a simple yet powerful data visualization library for Golang.
Apache ECharts is an awesome charting and visualization library, it supports adorable chart types and various interactive features. and there have many program languages interactive with Echarts, such as pyecharts, which go-echarts learns and has evolved a lot from, and the echarts4j either.

中文 README

🔰 Installation

Classic way to get go-echarts

# this may be not a good choice to use v2 go-echarts without gomod(GO111MODULE=off), the 
# next generation version management system 
# Technically, you could use go-echarts in the way below, if you have a better workaround, please let us know....

$ go get -u github.com/go-echarts/go-echarts/...
$ cd $go-echarts-project
$ mkdir v2 && mv charts components datasets opts render templates types v2

Use gomod style

$ go get -u github.com/go-echarts/go-echarts/v2/...

OR

# go.mod

require github.com/go-echarts/go-echarts/v2

⏳ Version

The go-echarts project is being developed under v2 version and the active codebase is on the master branch.

v1 and v2 are incompatible which means that you cannot upgrade go-echarts from v1 to v2 smoothly. But I think it is worth trying that new version.

Especially, when there contains mino changes (usually in enhancement), we will release the rc version before a standard release. So, if you upgrade your projects cross the rc versions, maybe need little adjust, and I believe it is worthy to do.

✨ Features

  • Clean and comprehensive API.
  • Visualize your data in 25+ different ways.
  • Highly configurable chart options.
  • Detailed documentation and a rich collection of examples.
  • Visualize your geographical data with 400+ maps.

📝 Usage

It's easy to get started with go-echarts with the handbook, go-echarts/examples and GoDocs.

In this example, we create a simple bar chart with only a few lines of code.

package main

import (
	"math/rand"
	"os"

	"github.com/go-echarts/go-echarts/v2/charts"
	"github.com/go-echarts/go-echarts/v2/opts"
)

// generate random data for bar chart
func generateBarItems() []opts.BarData {
	items := make([]opts.BarData, 0)
	for i := 0; i < 7; i++ {
		items = append(items, opts.BarData{Value: rand.Intn(300)})
	}
	return items
}

func main() {
	// create a new bar instance
	bar := charts.NewBar()
	// set some global options like Title/Legend/ToolTip or anything else
	bar.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
		Title:    "My first bar chart generated by go-echarts",
		Subtitle: "It's extremely easy to use, right?",
	}))

	// Put data into instance
	bar.SetXAxis([]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}).
		AddSeries("Category A", generateBarItems()).
		AddSeries("Category B", generateBarItems())
	// Where the magic happens
	f, _ := os.Create("bar.html")
	bar.Render(f)
}

And the generated bar.html is rendered as below. Isn't that cool!

Of course we can also start a listening web server with net/http.

package main

import (
	"math/rand"
	"net/http"

	"github.com/go-echarts/go-echarts/v2/charts"
	"github.com/go-echarts/go-echarts/v2/opts"
	"github.com/go-echarts/go-echarts/v2/types"
)

// generate random data for line chart
func generateLineItems() []opts.LineData {
	items := make([]opts.LineData, 0)
	for i := 0; i < 7; i++ {
		items = append(items, opts.LineData{Value: rand.Intn(300)})
	}
	return items
}

func httpserver(w http.ResponseWriter, _ *http.Request) {
	// create a new line instance
	line := charts.NewLine()
	// set some global options like Title/Legend/ToolTip or anything else
	line.SetGlobalOptions(
		charts.WithInitializationOpts(opts.Initialization{Theme: types.ThemeWesteros}),
		charts.WithTitleOpts(opts.Title{
			Title:    "Line example in Westeros theme",
			Subtitle: "Line chart rendered by the http server this time",
		}))

	// Put data into instance
	line.SetXAxis([]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}).
		AddSeries("Category A", generateLineItems()).
		AddSeries("Category B", generateLineItems()).
		SetSeriesOptions(charts.WithLineChartOpts(opts.LineChart{Smooth: true}))
	line.Render(w)
}

func main() {
	http.HandleFunc("/", httpserver)
	http.ListenAndServe(":8081", nil)
}

image

🔖 Gallery

bar boxplot effectScatter funnel gague geo graph heatmap kline line liquid map parallel pie radar scatter wordCloud bar3D line3D sankey scatter3D surface3D themeRiver overlap

For more information, please refer to handbook, go-echarts/examples and the GoDoc.

💡 Contribution

go-echarts is an open source project and built on the top of other open-source projects. Welcome all the kinds of contributions. No matter it is for typo fix, bug fix or big new features. Please do not hesitate to ask a question or send a pull request.

We strongly value documentation and integration with other projects, so we are very glad to accept improvements for these aspects.

❤️ Contributors

contributors

📃 License

MIT ©go-echarts

statsview's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

statsview's Issues

The stop method blocks the program

I'm calling this method

ViewManager.Stop()

ViewManager.Start() also calls the stop method internally

for {
		select {
		case <-ticker.C:
			viewer.StartRTCollect()
		case <-vm.done:
			vm.Stop()
			ticker.Stop()
			return
		}
	}

feature request: instead of port number have a route

Hi!

The access to the graphs is now by using a special port number. This is ok for local apps, but difficult for apps deployed remotely. Because those are behind firewalls and stuff. Or, in the case of Heroku, it is not possible to open (or select) a second port. A special route like '/debug/vars' would work better in those cases.

Enable CORS for remote debugging

When i am running a VM with a go application but want to see the results on the host machine, the frontend won't load due to CORS.

Can add custom routing function

Can add a custom routing function, like this

viewer.SetConfiguration(viewer.WithTheme(viewer.ThemeWalden), viewer.WithAddr("localhost:8087"),viewer.WithViewPath("/"))

ThemeWalden not declared by package viewer

Running statsview with the recomended configuration is giving me an error
ThemeWalden not declared by package viewer

I'm adding it as suggested before calling Start() but it seems to be missing something.

go func() {
	mgr := statsview.New()

	viewer.SetConfiguration(viewer.WithTheme(viewer.ThemeWalden), view.WithAddr("localhost:8087"))

	// Start() runs a HTTP server at `localhost:18066` by default.
	mgr.Start()

Gives me
ThemeWalden not declared by package viewer

When expecting to see a different theme and port.

Also not seeing more than two views when omitting the viewer line. I'm seeing Goroutines and Heap but not the others listed.

GC Number

Hi, this isn't exactly an issue, I'd just like to have an explaination about what is the "GC Number" in the charts.
Is it the number of garbage collection cycles? My app have an always increasing "GC Number" and I would like to know if this could be a problem.

Thank you.

Page won't show any graph and there is data race

Hi,

There is no error in Network tab but the graph won't show any data on http://localhost:18066/debug/statsview. However, http://localhost:18066/debug/pprof/ is fine otherwise. Not sure if it is related to the data race but when I start the app, I see data race at the beginning.

Thanks

Part of my code.

	...
	go func() {
		if err := srv.Start(); err != nil { // Running on 0.0.0.0:8001
			log.Fatal(err.Error())
		}
	}()

	mgr := statsview.New()
	go mgr.Start() // <-- DATARACE
	defer mgr.Stop()
	...
==================
WARNING: DATA RACE
Write at 0x00c0000deb00 by goroutine 26:
  github.com/go-echarts/statsview/viewer.(*StatsMgr).Tick()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/viewer/viewer.go:193 +0xbd
  github.com/go-echarts/statsview/viewer.(*StackViewer).Serve()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/viewer/stack.go:51 +0x69
  github.com/go-echarts/statsview/viewer.Viewer.Serve-fm()
      <autogenerated>:1 +0x75
  net/http.HandlerFunc.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2109 +0x4d
  net/http.(*ServeMux).ServeHTTP()
      /usr/local/go/src/net/http/server.go:2487 +0xc5
  github.com/rs/cors.(*Cors).Handler.func1()
      /Users/me/go/pkg/mod/github.com/rs/[email protected]/cors.go:236 +0x343
  net/http.HandlerFunc.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2109 +0x4d
  net/http.serverHandler.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2947 +0x641
  net/http.(*conn).serve()
      /usr/local/go/src/net/http/server.go:1991 +0xbe4
  net/http.(*Server).Serve.func3()
      /usr/local/go/src/net/http/server.go:3102 +0x58

Previous write at 0x00c0000deb00 by goroutine 27:
  github.com/go-echarts/statsview/viewer.(*StatsMgr).Tick()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/viewer/viewer.go:193 +0xbd
  github.com/go-echarts/statsview/viewer.(*GCNumViewer).Serve()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/viewer/gcnum.go:48 +0x69
  github.com/go-echarts/statsview/viewer.Viewer.Serve-fm()
      <autogenerated>:1 +0x75
  net/http.HandlerFunc.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2109 +0x4d
  net/http.(*ServeMux).ServeHTTP()
      /usr/local/go/src/net/http/server.go:2487 +0xc5
  github.com/rs/cors.(*Cors).Handler.func1()
      /Users/me/go/pkg/mod/github.com/rs/[email protected]/cors.go:236 +0x343
  net/http.HandlerFunc.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2109 +0x4d
  net/http.serverHandler.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2947 +0x641
  net/http.(*conn).serve()
      /usr/local/go/src/net/http/server.go:1991 +0xbe4
  net/http.(*Server).Serve.func3()
      /usr/local/go/src/net/http/server.go:3102 +0x58

Goroutine 26 (running) created at:
  net/http.(*Server).Serve()
      /usr/local/go/src/net/http/server.go:3102 +0x837
  net/http.(*Server).ListenAndServe()
      /usr/local/go/src/net/http/server.go:2999 +0xc4
  github.com/go-echarts/statsview.(*ViewManager).Start()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/statsview.go:36 +0x3d
  main.main.func3()
      /Users/me/dev/golang/blog/cmd/api/main.go:100 +0x39

Goroutine 27 (running) created at:
  net/http.(*Server).Serve()
      /usr/local/go/src/net/http/server.go:3102 +0x837
  net/http.(*Server).ListenAndServe()
      /usr/local/go/src/net/http/server.go:2999 +0xc4
  github.com/go-echarts/statsview.(*ViewManager).Start()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/statsview.go:36 +0x3d
  main.main.func3()
      /Users/me/dev/golang/blog/cmd/api/main.go:100 +0x39
==================

==================
WARNING: DATA RACE
Write at 0x000002015408 by goroutine 15:
  github.com/go-echarts/statsview/viewer.(*StatsMgr).polling()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/viewer/viewer.go:205 +0x329
  github.com/go-echarts/statsview/viewer.NewStatsMgr.func1()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/viewer/viewer.go:187 +0x39

Previous read at 0x000002015408 by goroutine 23:
  github.com/go-echarts/statsview/viewer.(*HeapViewer).Serve()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/viewer/heap.go:58 +0x372
  github.com/go-echarts/statsview/viewer.Viewer.Serve-fm()
      <autogenerated>:1 +0x75
  net/http.HandlerFunc.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2109 +0x4d
  net/http.(*ServeMux).ServeHTTP()
      /usr/local/go/src/net/http/server.go:2487 +0xc5
  github.com/rs/cors.(*Cors).Handler.func1()
      /Users/me/go/pkg/mod/github.com/rs/[email protected]/cors.go:236 +0x343
  net/http.HandlerFunc.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2109 +0x4d
  net/http.serverHandler.ServeHTTP()
      /usr/local/go/src/net/http/server.go:2947 +0x641
  net/http.(*conn).serve()
      /usr/local/go/src/net/http/server.go:1991 +0xbe4
  net/http.(*Server).Serve.func3()
      /usr/local/go/src/net/http/server.go:3102 +0x58

Goroutine 15 (running) created at:
  github.com/go-echarts/statsview/viewer.NewStatsMgr()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/viewer/viewer.go:187 +0x184
  github.com/go-echarts/statsview.New()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/statsview.go:87 +0x8c9
  main.main()
      /Users/me/dev/golang/blog/cmd/api/main.go:99 +0xb0e

Goroutine 23 (running) created at:
  net/http.(*Server).Serve()
      /usr/local/go/src/net/http/server.go:3102 +0x837
  net/http.(*Server).ListenAndServe()
      /usr/local/go/src/net/http/server.go:2999 +0xc4
  github.com/go-echarts/statsview.(*ViewManager).Start()
      /Users/me/go/pkg/mod/github.com/go-echarts/[email protected]/statsview.go:36 +0x3d
  main.main.func3()
      /Users/me/dev/golang/blog/cmd/api/main.go:100 +0x39
==================

Screenshot 2023-02-25 at 12 40 04

Screenshot 2023-02-25 at 12 40 14

Performance issues & Production environment use

hi.
I want to integrate it into my services。
My service is a high performance live streaming service。
I see that your program will call periodically (Runtime.ReadMemStats()).

This method says in the source code:

	stopTheWorld("read mem stats")

	systemstack(func() {
		readmemstats_m(m)
	})

	startTheWorld()

Looks like it will pause the program to collect information, shouldn't it be used in production?

Missing Charts

One of my users is reporting that he cannot see all the statsview charts on Windows. He's tried it on a couple of browsers with the same results. These are the screenshots he's given me:

firefox

chrome

I don't have access to Windows here so it is difficult to debug. Is this a known problem?

Project here:

https://github.com/JetSetIlly/Gopher2600

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.