Data variation from line-chart shown in percentages: Kibana 4

I've indexed some data from a couple of csv files, which contain information about a product: productID, price,stock, description and timestamp. I made a Line Chart (I am using Kibana 4.4.2), which shows me stock variation over time of a product with a given productID. Currently the line chart is showing me what the stock was for, lets say, each week. The content from the visualization -> Table looks like this:

@timestamp per week || 50th percentile of Quantity

August 31st 2015, 00:00:00.000 || 60
September 7th 2015, 00:00:00.000 || 60
September 14th 2015, 00:00:00.000 || 48
September 21st 2015, 00:00:00.000 || 60
September 28th 2015, 00:00:00.000 || 50
.............................................................................

I would like to know if there is a way to create the Line Chart so that it will show me in percentages how the stock variates from the previous week, something like 'in september 10th the stock was 23, in september the 17th the stock increased with 40% from september 10th, in september 24th the stock decreased with 10% from september the 17th' and so on (obviously in a graphical manner, not a written one :slight_smile: ) ?

Hey there, you can't do this with kibana, but you can do it with Timelion, a plugin for kibana.

  1. So to get the change I want to get the count of events this this week: .es(*)
  2. Then find the difference from last week, .es(*).subtract(.es(*, offset=-1w)).
  3. Then divide that number by last week's count: .es(*).subtract(.es(*, offset=-1w)).divide(.es(*, offset=-1w))
  4. And finally multiply by 100: .es(*).subtract(.es(*, offset=-1w)).divide(.es(*, offset=-1w)).multiply(100)

Now of course, if your count last week was 0 at any point, you'll end up with a missing bucket. Maybe you want to highlight times when stock dropped to 0. We can do that by adding a 2nd y-axis and simply drawing a red line at any point where the stock dropped to 0:

.es(*).if(ne, if=0, then=null, else=1).bars().yaxis(2, max=1)

This says,

  1. Pull all events .es(*)
  2. If the stock is-not-equal (ne) to 0, then set it to null, else set it to 1. .es(*).if(ne, if=0, then=null, else=1)
  3. Show the series as bars, on y-axis #2, with a max of 1 .es(*).if(ne, if=0, then=null, else=1).bars().yaxis(2, max=1)

Hope that helps!

3 Likes

Hello :slight_smile:
I've tried your implementation and it works very well, it's exactly what I needed.
Thank you so much :slight_smile: !