Angular 6 Ngx图,xAxis日期排序错误 [英] Angular 6 Ngx-charts, xAxis date sorting is wrong

查看:105
本文介绍了Angular 6 Ngx图,xAxis日期排序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对图表的x轴刻度进行排序.我尝试使用[xAxisTicks],但是没有用.我找不到与xAxisTicks相关的任何示例.我试图在其中分配一个变量,例如:

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.

图表对象(系列)

请参阅图表的x轴

推荐答案

除非您使用时间序列(请参见 https://github.com/swimlane/ngx-charts/issues/434 ),系列名称"只是字符串,当系列不能包含相同的名称"集.但是,您可以调整数据以填写缺失"系列条目

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
      }
    ]
  }
];

请参见 https://plnkr.co/edit/RQKpXjAYcocqpTUHZWUo

这篇关于Angular 6 Ngx图,xAxis日期排序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆