本文介绍了如何将格式从字符串更改为数字,除了数组中的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有谷歌图表以下数据,

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 " ",

$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]
           ]

如果只能使用谷歌图表的任何格式spcecifiers函数,而不是再次迭代它,这将是非常好的。这里是我的工作小提琴与哑数据没有双重,
,这是以字符串作为数字的演示

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. Here is my working fiddle with dummy data without double quets "", working Demoand this is demo with strings as numbers Demo with original data

我不能改变数据,因为它来自服务器调用,我正在添加基于用户点击的行。请任何人分享你的想法或小提琴。

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));






注释中提到的问题来自fn简写 =>

尝试用常规函数替换...

try replacing with regular function...

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

这篇关于如何将格式从字符串更改为数字,除了数组中的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 17:11