Angular 6 Ngx-charts, xAxis date sorting is wrong

2019-07-26 01:14发布

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

标签: ngx-charts
1条回答
叼着烟拽天下
2楼-- · 2019-07-26 01:52

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

查看更多
登录 后发表回答