Thanks for responding - I have a work-around for the first of the issues (null values).
I’ve created a dashboard below that you can use for testing.
This uses a Postgres database but can probably be adapted to any data.
How it works is you select values in the “Display” variable and then below you have two sets of graphs. The old “graph” panel is set to hide a series if every value is null (“three” is always null) and the SQL will act in two different ways depending on whether or not the variable is selected.
{
"__inputs": [],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "7.5.6"
},
{
"type": "panel",
"id": "graph",
"name": "Graph",
"version": ""
},
{
"type": "panel",
"id": "timeseries",
"name": "Time series",
"version": ""
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": null,
"iteration": 1632304610512,
"links": [],
"panels": [
{
"datasource": null,
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"graph": false,
"legend": false,
"tooltip": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 9,
"x": 0,
"y": 0
},
"id": 4,
"options": {
"graph": {},
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom"
},
"tooltipOptions": {
"mode": "single"
}
},
"pluginVersion": "7.5.6",
"targets": [
{
"format": "time_series",
"group": [],
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT $__unixEpochFrom() As time, 'one' AS metric, 1 AS value WHERE 'one' = ANY(ARRAY[${varDisplay}])\nUNION SELECT $__unixEpochTo(), 'one', 1 WHERE 'one' = ANY(ARRAY[${varDisplay}])\nUNION SELECT $__unixEpochFrom() As time, 'two' AS metric, 2 AS value WHERE 'two' = ANY(ARRAY[${varDisplay}])\nUNION SELECT $__unixEpochTo(), 'two', 2 WHERE 'two' = ANY(ARRAY[${varDisplay}])\nUNION SELECT $__unixEpochFrom() As time, 'three' AS metric, null AS value WHERE 'three' = ANY(ARRAY[${varDisplay}])\nUNION SELECT $__unixEpochTo(), 'three', null WHERE 'three' = ANY(ARRAY[${varDisplay}])\n",
"refId": "A",
"select": [
[
{
"params": [
"value_float"
],
"type": "column"
}
]
],
"table": "reporting_settings",
"timeColumn": "value_date",
"timeColumnType": "timestamp",
"where": [
{
"name": "$__timeFilter",
"params": [],
"type": "macro"
}
]
}
],
"title": "Time Series Visualization 1",
"type": "timeseries"
},
{
"datasource": null,
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"graph": false,
"legend": false,
"tooltip": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 9,
"x": 9,
"y": 0
},
"id": 5,
"options": {
"graph": {},
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom"
},
"tooltipOptions": {
"mode": "single"
}
},
"pluginVersion": "7.5.6",
"targets": [
{
"format": "time_series",
"group": [],
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT $__unixEpochFrom() As time, \n CASE WHEN 'one' = ANY(ARRAY[${varDisplay}]) THEN 1 END \"one\",\n CASE WHEN 'two' = ANY(ARRAY[${varDisplay}]) THEN 2 END \"two\",\n CASE WHEN 'three' = ANY(ARRAY[${varDisplay}]) THEN null::numeric END \"three\"\nUNION \nSELECT $__unixEpochTo() As time, \n CASE WHEN 'one' = ANY(ARRAY[${varDisplay}]) THEN 1 END \"one\",\n CASE WHEN 'two' = ANY(ARRAY[${varDisplay}]) THEN 2 END \"two\",\n CASE WHEN 'three' = ANY(ARRAY[${varDisplay}]) THEN null::numeric END \"three\"\n",
"refId": "A",
"select": [
[
{
"params": [
"value_float"
],
"type": "column"
}
]
],
"table": "reporting_settings",
"timeColumn": "value_date",
"timeColumnType": "timestamp",
"where": [
{
"name": "$__timeFilter",
"params": [],
"type": "macro"
}
]
}
],
"title": "Time Series Visualization 2",
"type": "timeseries"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fieldConfig": {
"defaults": {},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 9,
"w": 9,
"x": 0,
"y": 8
},
"hiddenSeries": false,
"id": 2,
"legend": {
"avg": false,
"current": false,
"hideEmpty": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.5.6",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"format": "time_series",
"group": [],
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT $__unixEpochFrom() As time, 'one' AS metric, 1 AS value WHERE 'one' = ANY(ARRAY[${varDisplay}])\nUNION SELECT $__unixEpochTo(), 'one', 1 WHERE 'one' = ANY(ARRAY[${varDisplay}])\nUNION SELECT $__unixEpochFrom() As time, 'two' AS metric, 2 AS value WHERE 'two' = ANY(ARRAY[${varDisplay}])\nUNION SELECT $__unixEpochTo(), 'two', 2 WHERE 'two' = ANY(ARRAY[${varDisplay}])\nUNION SELECT $__unixEpochFrom() As time, 'three' AS metric, null AS value WHERE 'three' = ANY(ARRAY[${varDisplay}])\nUNION SELECT $__unixEpochTo(), 'three', null WHERE 'three' = ANY(ARRAY[${varDisplay}])\n",
"refId": "A",
"select": [
[
{
"params": [
"value_float"
],
"type": "column"
}
]
],
"table": "reporting_settings",
"timeColumn": "value_date",
"timeColumnType": "timestamp",
"where": [
{
"name": "$__timeFilter",
"params": [],
"type": "macro"
}
]
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Graph Visualization 1",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:271",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:272",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fieldConfig": {
"defaults": {},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 9,
"w": 9,
"x": 9,
"y": 8
},
"hiddenSeries": false,
"id": 6,
"legend": {
"avg": false,
"current": false,
"hideEmpty": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.5.6",
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"format": "time_series",
"group": [],
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT $__unixEpochFrom() As time, \n CASE WHEN 'one' = ANY(ARRAY[${varDisplay}]) THEN 1 END \"one\",\n CASE WHEN 'two' = ANY(ARRAY[${varDisplay}]) THEN 2 END \"two\",\n CASE WHEN 'three' = ANY(ARRAY[${varDisplay}]) THEN null::numeric END \"three\"\nUNION \nSELECT $__unixEpochTo() As time, \n CASE WHEN 'one' = ANY(ARRAY[${varDisplay}]) THEN 1 END \"one\",\n CASE WHEN 'two' = ANY(ARRAY[${varDisplay}]) THEN 2 END \"two\",\n CASE WHEN 'three' = ANY(ARRAY[${varDisplay}]) THEN null::numeric END \"three\"\n",
"refId": "A",
"select": [
[
{
"params": [
"value_float"
],
"type": "column"
}
]
],
"table": "reporting_settings",
"timeColumn": "value_date",
"timeColumnType": "timestamp",
"where": [
{
"name": "$__timeFilter",
"params": [],
"type": "macro"
}
]
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Graph Visualization 2",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:271",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"$$hashKey": "object:272",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"schemaVersion": 27,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"allValue": null,
"current": {
"selected": true,
"tags": [],
"text": [
"one",
"three"
],
"value": [
"one",
"three"
]
},
"description": null,
"error": null,
"hide": 0,
"includeAll": false,
"label": "Display",
"multi": true,
"name": "varDisplay",
"options": [
{
"selected": true,
"text": "one",
"value": "one"
},
{
"selected": false,
"text": "two",
"value": "two"
},
{
"selected": true,
"text": "three",
"value": "three"
}
],
"query": "one,two,three",
"queryValue": "",
"skipUrlSync": false,
"type": "custom"
}
]
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Time Series vs Graph Visualization Test",
"uid": "JCWwVDHnk",
"version": 4
}