Use gridPos for scripted dashboard

Hi all,

I made a dashboard that looks like this :

And I want to make a script that makes the same dashboard, but on an older version of Grafana I used “dashboard.rows.push” to make dashboard looks the way I wanted but with the actual Grafana’s version my script makes dashboards looking like this :

As you can see on the first screenshot my panel is on two rows, is there an equivalent of “dashboard.rows.push” working with gridPos ? Or any other way that could help me ?

Thanks.

A row is now a sort of panel but in your case I don’t think you need rows at all. There is a panels array now instead of a rows array.

The way to handle the x,y coordinates and the height and width is the gridPos object. The grid is 24 slots wide so setting w to 24 is full width, 12 would be half and for the height each point is 30 pixels (so 10 would be 300 pixels).

See below for an example:

dashboard.panels.push({
    title: 'Events',
    type: 'graph',
    linewidth: 2,
    gridPos: {
      h: 10,
      w: 24,
      x: 0,
      y: 10,
    },
....

I noticed that the scripted dashboard examples with Grafana are out of date so I’ll update those and the docs.

2 Likes

Thanks for your help, I’m gonna try what you said. And thank you for updating the docs :slight_smile:

Hi,

Is there any way to create Grafana dashboard as code with Python using Influxdb as datasource. Already I tried with Grafana lib but it doesn’t support influx.

Thanks

I am adding the grid position as

{
title: ‘CPU Usage’,
type: ‘graph’,
linewidth: 2,
gridPos: {
x: 0,
y: 4,
w: 12,
h: 10
},
fill: 1,
datasource: ‘telegraf’,
targets: [ …
},

But when I open the file in grafana am getting json as

“gridPos”: {
“x”: 0,
“y”: 4,
“w”: 8,
“h”: 7
},

Did I miss anything?

2 Likes

I’m getting the same result as you. Did you fix it?
Thank you

I have the same issue with gridpos, in the same row we can use the span, ie:
panels: [{
title: ‘panel text 1’,
type: ‘text’,
height: ‘400px’,
span: 4,
fill: 1,
content: ‘# 1’
},{
title: ‘panel text 2’,
type: ‘text’,
height: ‘400px’,
span: 8,
fill: 1,
content: ‘# 2’
} …

1 Like

I generated the json for a dashboard with 120 panels, each line should present a {Text panel}, a {singlestat panel} and {2 gauge panels}.
Text panel has width 6, height 3.
All other panels has has height 3 and width 2.
When I paste the json with the arrays generated it seems to crash, as a lot of panels get overlaid.
if I input each panel json individually they work, from the second line on it starts get messing.
But when I past all its like chaos, several panels overlayd and singlestat and gauge panels assuming position and size of the Text panels.
What should be a good practice to follow in order to prevent this from happening.
the grid position and sizes of the panels looks mathematically correct.

Is there something I can do to prevent this issue from happening?