Bar chart with color by threshold

  • What Grafana version and what operating system are you using?
    10.2.0

  • What are you trying to achieve?
    I want a bar chart with a different color for any bar which exceeds a threshold.

  • How are you trying to achieve it?
    I made a bar chart with color scheme “from thresholds (by value)”.
    I set decimals to 1.
    I set the base color to blue and a threshold to red.
    I set the soft min/max to 115 and 125 to make it easier to see.

With the threshold set at 123 all bars are red:

With the threshold set at 124 all bars are blue:

The data comes from Prometheus query: voltageLC1{site="$site", room="$room", job="PDU 1"} / 100. The raw numbers look like 12171 so I divide by 100 to get the voltage.

  • Can you copy/paste the configuration(s) that you are having problems with?
{
  "datasource": {
    "uid": "fcdbb9cf-3c1a-4fe7-ae16-f58d776c91ff",
    "type": "prometheus"
  },
  "fieldConfig": {
    "defaults": {
      "custom": {
        "lineWidth": 1,
        "fillOpacity": 80,
        "gradientMode": "none",
        "axisPlacement": "auto",
        "axisLabel": "",
        "axisColorMode": "text",
        "axisBorderShow": false,
        "scaleDistribution": {
          "type": "linear"
        },
        "axisCenteredZero": false,
        "hideFrom": {
          "tooltip": false,
          "viz": false,
          "legend": false
        },
        "thresholdsStyle": {
          "mode": "line"
        },
        "axisSoftMax": 125,
        "axisSoftMin": 115
      },
      "color": {
        "mode": "thresholds"
      },
      "mappings": [],
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "color": "blue",
            "value": null
          },
          {
            "color": "red",
            "value": 124
          }
        ]
      },
      "unit": "volt",
      "decimals": 1
    },
    "overrides": []
  },
  "gridPos": {
    "h": 6,
    "w": 12,
    "x": 12,
    "y": 16
  },
  "id": 10,
  "interval": "1m",
  "options": {
    "orientation": "auto",
    "xTickLabelRotation": 0,
    "xTickLabelSpacing": 100,
    "showValue": "auto",
    "stacking": "none",
    "groupWidth": 0.7,
    "barWidth": 0.97,
    "barRadius": 0,
    "fullHighlight": false,
    "tooltip": {
      "mode": "single",
      "sort": "none"
    },
    "legend": {
      "showLegend": true,
      "displayMode": "list",
      "placement": "bottom",
      "calcs": [
        "min",
        "max"
      ]
    }
  },
  "targets": [
    {
      "datasource": {
        "type": "prometheus",
        "uid": "fcdbb9cf-3c1a-4fe7-ae16-f58d776c91ff"
      },
      "disableTextWrap": false,
      "editorMode": "code",
      "expr": "voltageLC1{site=\"$site\", room=\"$room\", job=\"PDU 1\"} / 100",
      "fullMetaSearch": false,
      "includeNullMetadata": true,
      "instant": false,
      "legendFormat": "{{job}}",
      "range": true,
      "refId": "A",
      "useBackend": false
    }
  ],
  "title": "PDU Voltage",
  "type": "barchart",
  "description": ""
}

Ah I figured it out! I just had to change the gradient mode to “scheme”

In case anyone is struggling like me to get this to work, make sure your visualisation type is “Bar chart” and not “Time series”.

For time series I was getting parts of the bar in different colours, not the whole bar. When I switched to bar chart it worked exactly as above.