Create a dashboard builder

The starting point for every SDK dashboard is the DashboardBuilder. You create one with a title, then chain configuration methods to set properties like UID, tags, refresh interval, and time range.

To create your dashboard builder, complete the following steps:

Go

  1. Open main.go and add the following code:

    Go
    package main
    
    import (
      "encoding/json"
      "log"
      "os"
    
      "github.com/grafana/grafana-foundation-sdk/go/cog"
      "github.com/grafana/grafana-foundation-sdk/go/common"
      "github.com/grafana/grafana-foundation-sdk/go/dashboard"
    )
    
    func main() {
      builder := dashboard.NewDashboardBuilder("My SDK Dashboard").
        Uid("my-sdk-dashboard").
        Tags([]string{"generated", "foundation-sdk"}).
        Refresh("5m").
        Time("now-1h", "now").
        Timezone(common.TimeZoneBrowser)
    }

TypeScript

  1. Open index.ts and add the following code:

    typescript
    import { DashboardBuilder } from '@grafana/grafana-foundation-sdk/dashboard';
    
    const builder = new DashboardBuilder('My SDK Dashboard')
      .uid('my-sdk-dashboard')
      .tags(['generated', 'foundation-sdk'])
      .refresh('5m')
      .time({ from: 'now-1h', to: 'now' })
      .timezone('browser');

What each method does

MethodPurpose
Uid / uidA stable identifier. Same UID means “update existing dashboard,” not “create a duplicate.”
Tags / tagsLabels for filtering dashboards in the UI. Useful for identifying code-generated ones.
Refresh / refreshHow often the dashboard auto-refreshes when open.
Time / timeThe default time range displayed when the dashboard loads.
Timezone / timezoneWhich timezone the dashboard uses for displaying times.

In the next milestone, you add panels with data queries to your dashboard.


page 4 of 8