Angular 6 Ngx-charts, xAxis date sorting is wrong

别来无恙 提交于 2019-12-24 11:13:05

问题


I need to sort x-axis ticks of the chart. I tried to use [xAxisTicks], but it didn't work. I couldn't find any example related with xAxisTicks. I tried to assign a variable inside of it like:

values = ["2012","2013","2014","2015","2016"];

Another interesting thing is, My series is already sorted but it still shows unsorted.

Chart object (series)

See chart's x-Axis


回答1:


Unless you're using a time series (see https://github.com/swimlane/ngx-charts/issues/434 ), the series 'names' are just strings and don't appear to get sorted when the series don't contain the same sets of 'names'. You can, however, adjust the data to fill in the 'missing' series entries,

export var multi = [
  {
    "name": "memzuc",
    "series": [
      {
        "name": "201801",  // Added
        "value": 0
      },
      {
        "name": "201802",  // Added
        "value": 0
      },
      {
        "name": "201803",
        "value": 350855
      },
      {
        "name": "201804",
        "value": 351673
      },
      {
        "name": "201805",
        "value": 368720
      },
      {
        "name": "201806",
        "value": 366941
      },
      {
        "name": "201807",
        "value": 387829
      },
    ]
  },

  {
    "name": "cwb",
    "series": [
      {
        "name": "201801",
        "value": 342300
      },
      {
        "name": "201802",
        "value": 337298
      },
      {
        "name": "201803",
        "value": 350855
      },
      {
        "name": "201804",
        "value": 359973
      },
      {
        "name": "201805",
        "value": 2179919
      },
      {
        "name": "201806",  // Added
        "value": 0
      },
      {
        "name": "201807",  // Added
        "value": 0
      }
    ]
  }
];

see https://plnkr.co/edit/RQKpXjAYcocqpTUHZWUo



来源:https://stackoverflow.com/questions/52205181/angular-6-ngx-charts-xaxis-date-sorting-is-wrong

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!