示例#1
0
func main() {
	width := 1200
	height := 300

	bgColor := util.Color{
		R: 1,
		G: 1,
		B: 1,
	}

	window := inertia.NewWindow(width, height, "my window", bgColor, 60)
	window.Show()

	ch, err := window.NewChart("my chart 1")
	if err != nil {
		log.Fatal(err)
	}
	ch.SetColor(util.GetRandomColor())
	ch.SetLineWidth(3)

	ch2, err := window.NewChart("my chart 2")
	if err != nil {
		log.Fatal(err)
	}
	ch2.SetColor(util.GetRandomColor())
	ch2.SetLineWidth(2)

	ch3, err := window.NewChart("my chart 3")
	if err != nil {
		log.Fatal(err)
	}
	ch3.SetColor(util.GetRandomColor())
	ch3.SetLineWidth(2)

	fillChart := func(c *chart.Chart, minY, maxY, minDur, maxDur int) {
		for {
			c.Push(util.GetRandom(minY, maxY))
			time.Sleep(time.Duration(util.GetRandom(minDur, maxDur)) * time.Millisecond)
		}
	}

	go fillChart(ch, 0, height/3, 50, 500)
	go fillChart(ch2, height/3, height/3*2, 40, 70)
	go fillChart(ch3, height/3*2, height, 50, 1500)

	select {}
}
示例#2
0
文件: chart.go 项目: alex-ant/inertia
// AddLine adds new point to chart and connects it to the previous one.
func (c *Chart) AddLine(x, y int) {
	if c.colorful {
		c.LineColor = util.GetRandomColor()
	}
	c.Draw(c.LastX, c.LastY, x, c.WindowH-y, c.LineColor.R, c.LineColor.G, c.LineColor.B, c.LineWidth)
	c.LastX = x
	c.LastY = c.WindowH - y
}