# Incorrect values order on the X-axis

**URL:** <https://discuss.elastic.co/t/incorrect-values-order-on-the-x-axis/215003>\
**Category:** Kibana\
**Created:** [January 14, 2020, 2:33pm UTC](https://discuss.elastic.co/t/incorrect-values-order-on-the-x-axis/215003 "2020-01-14T14:33:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anne\_Kim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anne_kim/32/47196_2.png) [@Anne\_Kim](https://discuss.elastic.co/u/Anne_Kim)\
**Post date:** [January 14, 2020, 2:33pm UTC](https://discuss.elastic.co/t/incorrect-values-order-on-the-x-axis/215003/1 "2020-01-14T14:33:37Z")

</div>

Hello,  
The X-axis values are ordered Alphabetically (Ascending), but the visualization is incorrect (see image attached):

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

Here is the visState:

```auto
{
  "title": "Characters damages per a day after registration",
  "type": "line",
  "params": {
    "addLegend": true,
    "addTimeMarker": false,
    "addTooltip": true,
    "categoryAxes": [
      {
        "id": "CategoryAxis-1",
        "labels": {
          "filter": true,
          "show": true,
          "truncate": 100,
          "rotate": 0
        },
        "position": "bottom",
        "scale": {
          "type": "linear"
        },
        "show": true,
        "style": {},
        "title": {},
        "type": "category"
      }
    ],
    "dimensions": {
      "x": {
        "accessor": 1,
        "format": {
          "id": "terms",
          "params": {
            "id": "number",
            "otherBucketLabel": "Other",
            "missingBucketLabel": "Missing"
          }
        },
        "params": {},
        "aggType": "terms"
      },
      "y": [
        {
          "accessor": 2,
          "format": {
            "id": "number"
          },
          "params": {},
          "aggType": "avg"
        },
        {
          "accessor": 3,
          "format": {
            "id": "number"
          },
          "params": {},
          "aggType": "avg"
        }
      ],
      "splitRow": [
        {
          "accessor": 0,
          "format": {
            "id": "terms",
            "params": {
              "id": "string",
              "otherBucketLabel": "Other",
              "missingBucketLabel": "Missing"
            }
          },
          "params": {},
          "aggType": "terms"
        }
      ]
    },
    "grid": {
      "categoryLines": false,
      "valueAxis": "ValueAxis-1"
    },
    "labels": {
      "show": true
    },
    "legendPosition": "top",
    "orderBucketsBySum": false,
    "radiusRatio": 75,
    "seriesParams": [
      {
        "data": {
          "id": "1",
          "label": "Damage dealt"
        },
        "drawLinesBetweenPoints": true,
        "interpolate": "linear",
        "mode": "normal",
        "show": "true",
        "showCircles": true,
        "type": "histogram",
        "valueAxis": "ValueAxis-1"
      },
      {
        "data": {
          "id": "2",
          "label": "Damage received"
        },
        "drawLinesBetweenPoints": true,
        "interpolate": "linear",
        "mode": "normal",
        "show": true,
        "showCircles": true,
        "type": "histogram",
        "valueAxis": "ValueAxis-1"
      }
    ],
    "times": [],
    "type": "line",
    "valueAxes": [
      {
        "id": "ValueAxis-1",
        "labels": {
          "filter": false,
          "rotate": 0,
          "show": true,
          "truncate": 100
        },
        "name": "LeftAxis-1",
        "position": "left",
        "scale": {
          "defaultYExtents": false,
          "mode": "normal",
          "type": "linear"
        },
        "show": true,
        "style": {},
        "title": {
          "text": "Average damage_dealt_amount"
        },
        "type": "value"
      }
    ],
    "thresholdLine": {
      "show": false,
      "value": 10,
      "width": 1,
      "style": "full",
      "color": "#34130C"
    }
  },
  "aggs": [
    {
      "id": "1",
      "enabled": true,
      "type": "avg",
      "schema": "metric",
      "params": {
        "field": "damage_dealt_amount",
        "customLabel": "Damage dealt"
      }
    },
    {
      "id": "2",
      "enabled": true,
      "type": "avg",
      "schema": "metric",
      "params": {
        "field": "damage_received_amount",
        "customLabel": "Damage received"
      }
    },
    {
      "id": "3",
      "enabled": true,
      "type": "terms",
      "schema": "segment",
      "params": {
        "field": "days_after_registration",
        "orderBy": "_key",
        "order": "asc",
        "size": 99999,
        "otherBucket": true,
        "otherBucketLabel": "Other",
        "missingBucket": true,
        "missingBucketLabel": "Missing"
      }
    },
    {
      "id": "4",
      "enabled": true,
      "type": "terms",
      "schema": "split",
      "params": {
        "field": "character_name.keyword",
        "orderBy": "_key",
        "order": "asc",
        "size": 12,
        "otherBucket": true,
        "otherBucketLabel": "Other",
        "missingBucket": true,
        "missingBucketLabel": "Missing",
        "row": true
      }
    }
  ]
}

```

What's the problem?

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [January 14, 2020, 8:54pm UTC](https://discuss.elastic.co/t/incorrect-values-order-on-the-x-axis/215003/2 "2020-01-14T20:54:46Z")

</div>

It looks like your `days_after_registration` is being treated as text instead of a number, where the first character matters. So for example, `100` is sorted before `20` because the character `1` comes first. So you have two options:

1. Change this to a number field
2. Use a scripted field to change the data type to a number

Once it's a number, the sorting will be numeric.

---

<div class="post-metadata">

**Author:** ![Anne\_Kim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anne_kim/32/47196_2.png) [@Anne\_Kim](https://discuss.elastic.co/u/Anne_Kim)\
**Post date:** [January 15, 2020, 12:17pm UTC](https://discuss.elastic.co/t/incorrect-values-order-on-the-x-axis/215003/3 "2020-01-15T12:17:38Z")

</div>

The field is already marked as number:

 ![](https://us1.discourse-cdn.com/elastic/original/3X/e/b/eb55f1be96d4d1848196d50e2c4ac0a5e29fea5c.png)  
An even if it was not a number, the order of X-axis values is not alphabetical (see the highlighted areas):  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/5/d/5d6bb7e0c5a663783e64181f3ada6b97b93fb552.png)

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [January 15, 2020, 2:56pm UTC](https://discuss.elastic.co/t/incorrect-values-order-on-the-x-axis/215003/4 "2020-01-15T14:56:53Z")

</div>

Looked into this a bit more, and my setup is basically the same except that I have denser data than you do. You might be experiencing some kind of bug in our chart library, and my guess is that the split chart is causing it. What happens if you remove the split chart, does it sort correctly?

---

<div class="post-metadata">

**Author:** ![Anne\_Kim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anne_kim/32/47196_2.png) [@Anne\_Kim](https://discuss.elastic.co/u/Anne_Kim)\
**Post date:** [January 16, 2020, 2:48pm UTC](https://discuss.elastic.co/t/incorrect-values-order-on-the-x-axis/215003/5 "2020-01-16T14:48:31Z")

</div>

Yes, it seems that you're right! I've removed the split chart

 ![](https://us1.discourse-cdn.com/elastic/original/3X/0/e/0e55aa7f52e3d23a0408285e2255ffa244e973c0.png)

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [January 16, 2020, 6:21pm UTC](https://discuss.elastic.co/t/incorrect-values-order-on-the-x-axis/215003/6 "2020-01-16T18:21:26Z")

</div>

I filed a bug report for this. I think your use of alphabetical sorting is not a case we had considered. [https://github.com/elastic/kibana/issues/55089](https://github.com/elastic/kibana/issues/55089)

---

<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:** [February 13, 2020, 6:21pm UTC](https://discuss.elastic.co/t/incorrect-values-order-on-the-x-axis/215003/7 "2020-02-13T18:21:38Z")

</div>

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