In this tutorial, you'll learn how to:
- Install FyneSimpleChart
- Set up your development environment
- Create your first simple chart
- Run and view your chart
Time to complete: 10 minutes
- Go 1.22.0 or later installed
- Basic Go programming knowledge
- Terminal/command line familiarity
First, ensure you have Go installed:
go versionYou should see output like: go version go1.22.0 darwin/amd64
Create a new directory for your project:
mkdir my-chart-app
cd my-chart-app
go mod init my-chart-appInstall the library and its dependencies:
go get github.com/alexiusacademia/fynesimplechart
go get fyne.io/fyne/v2Create a file named main.go:
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"github.com/alexiusacademia/fynesimplechart"
)
func main() {
// Create a new Fyne application
a := app.New()
w := a.NewWindow("My First Chart")
w.Resize(fyne.NewSize(600, 400))
// Create some data points
nodes := []fynesimplechart.Node{
*fynesimplechart.NewNode(1, 2),
*fynesimplechart.NewNode(2, 4),
*fynesimplechart.NewNode(3, 3),
*fynesimplechart.NewNode(4, 5),
*fynesimplechart.NewNode(5, 7),
}
// Create a plot
plot := fynesimplechart.NewPlot(nodes, "My Data")
// Create the chart widget
chart := fynesimplechart.NewGraphWidget([]fynesimplechart.Plot{*plot})
// Display the chart
w.SetContent(chart)
w.ShowAndRun()
}Run your application:
go run main.goYou should see a window with your first chart displaying 5 data points with:
- Grid lines
- Axis labels with numeric values
- A legend showing "My Data"
- A border around the plot area
Let's break down what each part does:
nodes := []fynesimplechart.Node{
*fynesimplechart.NewNode(1, 2), // X=1, Y=2
*fynesimplechart.NewNode(2, 4), // X=2, Y=4
// ...
}Each Node represents a point with X and Y coordinates.
plot := fynesimplechart.NewPlot(nodes, "My Data")A Plot contains your data points and a title that appears in the legend.
chart := fynesimplechart.NewGraphWidget([]fynesimplechart.Plot{*plot})The GraphWidget can contain multiple plots (we'll cover this in Tutorial 5).
Solution: Run go mod tidy to download dependencies.
Solution: Make sure you have the required system dependencies for Fyne:
- macOS: Xcode command line tools
- Linux: gcc, libgl1-mesa-dev, xorg-dev
- Windows: gcc via TDM-GCC or similar
Solution: Use chart.Resize() or w.Resize() to set a larger size:
chart.Resize(fyne.NewSize(800, 600))You've created your first chart with FyneSimpleChart!
- ✅ How to install FyneSimpleChart
- ✅ How to create data points
- ✅ How to create a plot
- ✅ How to display a chart in a window
Continue to Tutorial 2: Basic Scatter Plot to learn more about scatter plot features and customization.
// Basic chart template
nodes := []fynesimplechart.Node{
*fynesimplechart.NewNode(x, y),
}
plot := fynesimplechart.NewPlot(nodes, "Title")
chart := fynesimplechart.NewGraphWidget([]fynesimplechart.Plot{*plot})