简体   繁体   English

如何将格式更改为字符串中的数字,但数组中的第一行除外

[英]How to change format to number from string, except first row in array

Hi I have google chart with following data, 嗨我有谷歌图表与以下数据,

$scope.datax =[
       ["Release Date","R1","R2","R3"],
          ["Mon Apr 11 00:00:00 IST 2016","20","13","70"],
          ["Wed May 11 00:00:00 IST 2016","20","13","60"],
          ["Sat Jun 11 00:00:00 IST 2016","20","13","50"]
       ]

I need this format to like following i,e numbers should not contain quotes " ", 我需要这种格式喜欢以下i,e数字不应该包含引号“”,

$scope.datax =[
           ["Release Date","R1","R2","R3"],
              ["Mon Apr 11 00:00:00 IST 2016", 20, 13, 70],
              ["Wed May 11 00:00:00 IST 2016", 20, 13, 60],
              ["Sat Jun 11 00:00:00 IST 2016", 20, 13, 50]
           ]

It will be really good if this can be done using any of format spcecifiers function of google chart only rather than iterating it again. 如果可以使用谷歌图表的任何格式spcecifiers功能,而不是再次迭代它,这将是非常好的。 Here is my working fiddle with dummy data without double quets "", working Demo and this is demo with strings as numbers Demo with original data 这是我的工作小提琴与虚拟数据没有双quets“”, 工作演示 ,这是演示与字符串作为数字演示与原始数据

I cant change data because its coming from server call and I am adding rows based on clicks made by user. 我无法更改数据,因为它来自服务器调用,我根据用户点击添加行。 Please anyone share you idea or fiddle. 请有人分享你的想法或小提琴。 Thanks in advance. 提前致谢。

New solution, not that agressive in converting: 新的解决方案,而不是转换中的激进:

 $scope.datax=$scope.datax.map(row=>row.map(e=>+e||e));

Old solution, wich also converted dates... 旧解决方案,也转换日期...

$scope.datax=$scope.datax.map(row=>row.map(e=>parseInt(e,10)||e));

the problem noted in the comment is from the fn shorthand => 注释中提到的问题来自fn shorthand =>

try replacing with regular function... 尝试用常规功能替换......

$scope.datax=$scope.datax.map(function (row) {
  return row.map(function (e) {
    return +e||e;
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM