# Count active docs and display by date in Line Chart

**URL:** https://discuss.elastic.co/t/count-active-docs-and-display-by-date-in-line-chart/251129
**Category:** Kibana
**Created:** [October 6, 2020, 1:17pm UTC](https://discuss.elastic.co/t/count-active-docs-and-display-by-date-in-line-chart/251129 "2020-10-06T13:17:16Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![r97](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@r97](https://discuss.elastic.co/u/r97)
#### Post date: [October 6, 2020, 1:17pm UTC](https://discuss.elastic.co/t/count-active-docs-and-display-by-date-in-line-chart/251129/1 "2020-10-06T13:17:16Z")

</div>

Hi,

I have an index with the fields: @timestamp, boolean: active and solved\_date (see below).  
If I import the values, the solved\_date field is not set and the boolean is true.

When I want to make the document inactive I update the solved\_date and i set the boolean to false.

What is the best way to create a LineChart that counts the active objects by date?

```auto
Imported: 
{
      "type" : "typename",
      "active" : true,
      "@timestamp" : "2020-09-29T07:03:55.857Z",
      "solved_date" : "",
}

Status Changed: 
{
      "type" : "typename",
      "active" : false,
      "@timestamp" : "2020-09-29T07:03:55.857Z",
      "solved_date" : "2020-10-05T07:03:55.857Z",
}

```

---

<div class="post-metadata">

### Author: ![cheiligers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cheiligers/32/73114_2.png) [@cheiligers](https://discuss.elastic.co/u/cheiligers)
#### Post date: [October 6, 2020, 5:42pm UTC](https://discuss.elastic.co/t/count-active-docs-and-display-by-date-in-line-chart/251129/2 "2020-10-06T17:42:41Z")

</div>

@r97 Welcome to the Discuss forum!

A line chart shows a change in something, so I'm not sure what you're actually trying to achieve. If you want to show the _change_ in the number of objects that have `"active": true ` over time, then you could create a basic histogram of the documents (the objects) and add a filter to only show those that have `active: true`.

The type of chart you can create depends on the version of the stack you're running and if you're running under a basic (or higher) license vs oss.

Here are a few links that might help get you started with Visualizations in Kibana:

- [Visualizations docs](https://www.elastic.co/guide/en/kibana/current/visualize.html) (you can change the version on the right hand side of the page)
- [Visualizations tutorial](https://www.elastic.co/guide/en/kibana/current/tutorial-visualizing.html)
- [Visualizations Video](https://www.elastic.co/webinars/kibana-101-get-started-with-visualizations)

---

<div class="post-metadata">

### Author: ![r97](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@r97](https://discuss.elastic.co/u/r97)
#### Post date: [October 7, 2020, 9:09am UTC](https://discuss.elastic.co/t/count-active-docs-and-display-by-date-in-line-chart/251129/3 "2020-10-07T09:09:49Z")

</div>

Thanks for your reaction. But it doesn't solve the problem. The problem is that I need to count the active ones between the created and closed dates. Because the boolean changes to false while the value gets updated. So I want to see the view with a date and how many active items there are on this date. Like i have 3 issues with the dates:

Issue opened on 10-05-2020  
issue closed on 25-05-2020

I want to see the count (3) in the Line Graph between those dates.  
I'm on version 7.9.1 basic licence

---

<div class="post-metadata">

### Author: ![cheiligers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cheiligers/32/73114_2.png) [@cheiligers](https://discuss.elastic.co/u/cheiligers)
#### Post date: [October 7, 2020, 1:54pm UTC](https://discuss.elastic.co/t/count-active-docs-and-display-by-date-in-line-chart/251129/4 "2020-10-07T13:54:50Z")

</div>

@r97, I'm trying to get a mental picture of the graphs you want and need to make sure I'm on the same page as you: Do you want a line chart with dates on the x-axis and the count of active items on the y axis? A graph like that will show the number of active items there are on any particular date.

If that's the case, could you give a mocked example of the items? If not, I can try to mock up some data based on the example above.

---

<div class="post-metadata">

### Author: ![r97](https://avatars.discourse-cdn.com/v4/letter/r/e47774/32.png) [@r97](https://discuss.elastic.co/u/r97)
#### Post date: [October 7, 2020, 2:12pm UTC](https://discuss.elastic.co/t/count-active-docs-and-display-by-date-in-line-chart/251129/5 "2020-10-07T14:12:31Z")

</div>

Below is what I created with docs from another mock index. I want to do the same with the index structure listed in my first post. The issue is structuring/filtering the data to count the right numbers from active objects and the inactive objects between the dates.

I hope you can help me with that.

 ![Linegraph](https://us1.discourse-cdn.com/elastic/original/3X/a/f/af19109e1dbfdefceb5e2910cf16c9931ee6411d.png)

---

<div class="post-metadata">

### Author: ![cheiligers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cheiligers/32/73114_2.png) [@cheiligers](https://discuss.elastic.co/u/cheiligers)
#### Post date: [October 7, 2020, 4:00pm UTC](https://discuss.elastic.co/t/count-active-docs-and-display-by-date-in-line-chart/251129/6 "2020-10-07T16:00:45Z")

</div>

That mocked data vis looks great! I think you should be able to create the visualization reasonably easily using a Line graph:

1. Create a new Line visualization using the index that contains the data
2. Use a Date Histogram as your x-axis aggregation with the timestamp as your field. You should be able to leave the minimum interval as auto (or change it later for more/less granularity).
3. Use a count as your y-axis Metric
4. Using the global filter option right at the top of the page, below the search bar, add a filter with Field = active and the value as true.

The visualization will give you a count of the number of 'active' items for each date because we're plotting all the items and then filtering out those that are closed.

If you want to plot the sum of items over time that are active, I recommend using TSVB with a filter ratio of the number of active items that are true divided by all the items we have by that date. You might need to create some additional fields to plot those values though (using a sum aggregation in a pipeline for the total doc count you have per date). There's a Discuss post that covered something similar [here](https://discuss.elastic.co/t/visual-builder-time-series-filter-ratio-group-by-terms/213081/2).

I hope that gives you what you're looking for.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 4, 2020, 4:00pm UTC](https://discuss.elastic.co/t/count-active-docs-and-display-by-date-in-line-chart/251129/7 "2020-11-04T16:00:45Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
