Postgres get an active amount of object during the time range

Hello,
I have next table in Postgres database, I need to show an amount and duration of active task on grafana graph.
image

Can you please help. What script should be to create this graph?
Should be something like this:

Thanks.

You can use this plugin

and next query:

SELECT 
id AS metric,
1 as value,
start as time
FROM table
WHERE $timeFilter(start)
union 
SELECT 
id AS metric,
0 as value,
stop as time
FROM table
WHERE stop is not null and $timeFilter(stop)