# X axis range wrong

**URL:** https://discuss.elastic.co/t/x-axis-range-wrong/271642
**Category:** Kibana
**Tags:** vega
**Created:** [April 29, 2021, 12:47pm UTC](https://discuss.elastic.co/t/x-axis-range-wrong/271642 "2021-04-29T12:47:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![David\_Mohamad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_mohamad/32/85090_2.png) [@David\_Mohamad](https://discuss.elastic.co/u/David_Mohamad)
#### Post date: [April 29, 2021, 12:47pm UTC](https://discuss.elastic.co/t/x-axis-range-wrong/271642/1 "2021-04-29T12:47:51Z")

</div>

What is the right way to set the range of the X axis to the minimum and maximum value of the selected time range.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/1/d1908c4ae9e2e26f30fbad9c79c842cf57c95029.png)

This is what I have at the moment.  
If I select 2 days ago in the timefilter, it should show me the dates of 2 days ago even tho there is no data.

```auto
{
  $schema: https://vega.github.io/schema/vega/v5.json
  autosize: {
    type: fit
    resize: false
  }
  padding: auto
  data: [
    {
      name: elastic_src
      url: {
        index: index-*
        body: {
          query: {
            bool: {
              must: [
                %dashboard_context-must_clause%
                {
                  range: {
                  @timestamp: {
                      %timefilter%: true
                    }
                  }
                }
              ]
              must_not: [
                %dashboard_context-must_not_clause%
              ]
              filter: [
                %dashboard_context-filter_clause%
                {
                  term: {
                    ag.auth.action: logout
                  }
                }
                {
                  exists: {
                    field: ag.auth.logintime
                  }
                }
              ]
            }
          }
          fields: [
            source.user.name
            ag.auth.totaltime
            {
              field: @timestamp
              format: epoch_millis
            }
            {
              field: ag.auth.logintime
              format: epoch_millis
            }
          ]
          
          _source: "false"
        }
      }
      format: {
        property: hits.hits
      }
    }
  ]
  scales: [
    {
      name: xscale
      type: time
      domain: {
        data: elastic_src
        fields:[ 
          fields["ag.auth.logintime"][0]
          fields["@timestamp"][0]
        ]
      }
      range: width
      padding: 10
      round: true
    }
    {
      name: yscale
      type: band
      domain: {
        data: elastic_src
        field: fields["source.user.name"][0]
      }
      padding: 1
      nice: true
      range: height
    }
  ]
  axes: [
    {
      orient: bottom
      scale: xscale
      format: %d/%m/%y %H %M %S
      encode: {
        labels: {
          update: {
            angle: {
              value: -50
            }
            fontSize: {
              value: 10
            }
            align: {
              value: right
            }
          }
        }
      }
    }
    {
      orient: left
      grid: true
      scale: yscale
    }
  ]
  marks: [
    {
      type: symbol
      from: {
        data: elastic_src
      }
      encode: {
        enter: {
          x: {
            scale: xscale
            field: fields["ag.auth.logintime"][0]
          }
          y: {
            scale: yscale
            field: fields["source.user.name"][0]
          }
          fill: {
            value: steelblue
          }
        }
      }
    }
    {
      type: symbol
      from: {
        data: elastic_src
      }
      encode: {
        enter: {
          x: {
            scale: xscale
            field: fields["@timestamp"][0]
          }
          y: {
            scale: yscale
            field: fields["source.user.name"][0]
          }
          fill: {
            value: red
          }
        }
      }
    }
    {
      type: rect
      from: {
        data: elastic_src
      }
      encode: {
        enter: {
          x: {
            scale: xscale
            field: fields["ag.auth.logintime"][0]
          }
          x2: {
            scale: xscale
            field: fields["@timestamp"][0]
          }
          yc: {
            scale: yscale
            field: fields["source.user.name"][0]
          }
          height: {
            value: 5
          }
          fill: {
            value: "#557"
          }
        }
      }
    }
  ]
}

```

Thanks in advance.

---

<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: [May 27, 2021, 12:48pm UTC](https://discuss.elastic.co/t/x-axis-range-wrong/271642/2 "2021-05-27T12:48:50Z")

</div>

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