grafana / grafonnet-lib

Jsonnet library for generating Grafana dashboard files.
https://grafana.github.io/grafonnet-lib/
Apache License 2.0
1.08k stars 217 forks source link

How to add graphPanel on same row ? #339

Closed NicoAdrian closed 3 years ago

NicoAdrian commented 3 years ago

I want to iterate over an array of 12 items and over an array of 2 items. I have this code:

local grafana = import 'grafonnet/grafana.libsonnet';
local dashboard = grafana.dashboard;
local graphPanel = grafana.graphPanel;
local graphite = grafana.graphite;

local something12 = ["%02d" % i for i in std.range(1, 12)];
local something2 = ["foo", "bar"];

dashboard.new(
      'Test dashboard',
      uid='test-dashboard',
      editable=true,
      time_from='now-6h',
      time_to='now-1m',
    ).addPanels([
        graphPanel.new(
          'blabla %s and %s' %  [item12, item2],
          datasource='something',
          legend_alignAsTable=true,
          legend_current=true,
          legend_max=true,
          legend_hideEmpty=true,
          legend_hideZero=true,
          legend_values=true,
          sort='decreasing',
          nullPointMode='null as zero',
          formatY1='bps',
          min='0',
        ).addTarget(
            graphite.target(
              target='mytarget',
            )
        )
        {gridPos: {x: 0, y: 0, w: 30, h: 10 }},
        for item12 in something12 for item2 in something2
      ]
    )

I want both item2 graphs to be on same row and then a new row for next item12 etc. The addRow methods creates a collapsed row, but this is not what I want, I want the graphs to be on same line like this: Capture

NicoAdrian commented 3 years ago

Ok I figured it out. I need to use gridPos