-
Can anyone provide a sample code that dynamically updates the plot content? Here's my code, it won't work package main
import (
"cogentcore.org/core/core"
"cogentcore.org/core/plot/plotcore"
"fmt"
"math/rand"
"time"
)
func main() {
b := core.NewBody()
type Data struct {
Time float32
Users float32
Profit float32
}
var datas []Data
pe := plotcore.NewPlotEditor(b).SetSlice(datas)
go func() {
for {
datas = append(datas, Data{
Time: float32(len(datas)),
Users: rand.Float32(),
Profit: rand.Float32(),
})
fmt.Println(datas)
//pe.Update()
//pe.UpdatePlot()
pe.GoUpdatePlot()
time.Sleep(1 * time.Second)
}
}()
b.RunMainWindow()
}
|
Beta Was this translation helpful? Give feedback.
Answered by
kkoreilly
Dec 15, 2024
Replies: 1 comment 1 reply
-
The underlying representation of a plot is a |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
wingofsky
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The underlying representation of a plot is a
tensor.Table
, andSetSlice
just converts to that, so you need to callpe.SetSlice(datas)
again in your inner loop to get it to update correctly. The performance of that should still be good.