title: Plot derivative at correct time using influxdb/grafana
body: <p>I’m tracking my energy usage, amongst which a heat meter measuring usage in Joule. I want to calculate the heating power (in Watt), which works well with the <code>DERIVATIVE()</code> function.</p>
  
  <p>The problem is that the derivative is returned on the latter of two timestamps describing the data, which when combined with the staircase plot of Grafana shows the derivative for the next time delta instead of the current.</p>
  
  <p>How can I:</p>
  
  <ol>
  <li>Make Influxdb show the derivative on the first timestamp of the data? (Or alternatively: shift timestamps of a query?)</li>
  <li>Make Grafana plot staircase graphs extending the value left instead of right?</li>
  </ol>
  
  <p><strong>Graphical example</strong></p>
  
  <p><a href="https://i.stack.imgur.com/eLxUc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eLxUc.png" alt="Heat meter power calculated using Influxdb derivative() and shown with Grafana staircase line plot, where power is shown on wrong range"></a></p>
  
  <p><strong>Textual example</strong></p>
  
  <p>The following heat meter readings in influxdb</p>
  
  <pre><code>08:00,    0 Joule
  09:00, 3600 Joule
  19:00, 7200 Joule
  </code></pre>
  
  <p>will give</p>
  
  <pre><code>09:00, 1.0 Watt (which refers to 08:00-09:00)
  18:00, 0.1 Watt (which refers to 09:00-18:00)
  </code></pre>
  
  <p>which Grafana (as staircase) will plot as</p>
  
  <pre><code>08:00-09:00, Null (should be 1.0)
  09:00-18:00, 1.0  (should be 0.1)
  18:00-,      0.1  (should be Null)
  </code></pre>