每当Google有主要版本的图表库时,都会发生事情中断。下面的代码大约3年前开始实施,并于几年运行良好,并在过去一年中它打破了这样Google Table Chart Number当使用带逗号的格式化数字值时,格式化显示NaN
我填充数据表以及与此代码格式的数字
var formatter = new google.visualization.NumberFormat({pattern:'#,###.##'});
var cl = jsonChartData.rows[0].c.length;
for (var c=0;c<cl;c++) {
if (jsonChartData.cols[c].type == 'number'){
formatter.format(popDataTable, c);
}
}
和这种运作良好,并会产生这样的结果:v: 6155177.2549019605, f: '6,155,177.25'
,并通过文档这里Google Table Chart,这里Generic formatters支持,并在这里ICU 58.1
我使用以下代码
var tabOpt = {
width: '100%'
,allowHtml: true
,cssClassNames: {
tableRow: 'chartTabRow'
,oddTableRow: 'chartTabRow'
,headerRow: 'chartHeadRow'
,tableCell: 'chartTabRow'
,headerCell: 'chartHeadRow'
}
};
var wdt = popDataTable;
wdt.sort([
{column: colID(wdt, 'sumlev')}
,{column: colID(wdt, 'estyear')}
,{column: colID(wdt, 'estdata')}
,{column: popFactCol, desc: true}]);
dView = new google.visualization.DataView(wdt);
dView.setRows(dView.getFilteredRows([
{column: colID(dView, 'sumlev'), value: '010'}
,{column: colID(dView, 'estdata'), value: popFact}
,{column: colID(dView, 'estyear'), value: popFactYear}]));
var jsonPopParams = {
"cols":
[
{"id":"","label":"Parameter(N)","pattern":"","type":"string"},
{"id":"","label":"Value","pattern":"","type":"number"}
]
,
"rows":
[
{"c":
[
{"v":"N","f":null},
{"v":0,"f":null}
]
},
{"c":
[
{"v":"Sum","f":null},
{"v":0,"f":null}
]
},
{"c":
[
{"v":"Min","f":null},
{"v":0,"f":null}
]
},
{"c":
[
{"v":"Max","f":null},
{"v":0,"f":null}
]
},
{"c":
[
{"v":"Range","f":null},
{"v":0,"f":null}
]
},
{"c":
[
{"v":"Mean","f":null},
{"v":0,"f":null}
]
},
{"c":
[
{"v":"Median","f":null},
{"v":0,"f":null}
]
},
{"c":
[
{"v":"Variance","f":null},
{"v":0,"f":null}
]
},
{"c":
[
{"v":"Standard Dev","f":null},
{"v":0,"f":null}
]
},
{"c":
[
{"v":"Skewness","f":null},
{"v":0,"f":null}
]
},
{"c":
[
{"v":"Kurtosis","f":null},
{"v":0,"f":null}
]
}]
,
"p":null
};
jsonPopParams.rows[0].c[1].f = dView.getFormattedValue(0, colID(dView, 'pn'));
jsonPopParams.rows[1].c[1].f = dView.getFormattedValue(0, colID(dView, 'psum'));
jsonPopParams.rows[2].c[1].f = dView.getFormattedValue(0, colID(dView, 'pmin'));
jsonPopParams.rows[3].c[1].f = dView.getFormattedValue(0, colID(dView, 'pmax'));
jsonPopParams.rows[4].c[1].f = dView.getFormattedValue(0, colID(dView, 'prange'));
jsonPopParams.rows[5].c[1].f = dView.getFormattedValue(0, colID(dView, 'pmean'));
jsonPopParams.rows[6].c[1].f = dView.getFormattedValue(0, colID(dView, 'pmedian'));
jsonPopParams.rows[7].c[1].f = dView.getFormattedValue(0, colID(dView, 'pvariance'));
jsonPopParams.rows[8].c[1].f = dView.getFormattedValue(0, colID(dView, 'pstndev'));
jsonPopParams.rows[9].c[1].f = dView.getFormattedValue(0, colID(dView, 'pskew'));
jsonPopParams.rows[10].c[1].f = dView.getFormattedValue(0, colID(dView, 'pkurt'));
var tblChart = new google.visualization.Table(document.getElementById(paramDiv));
wdt = new google.visualization.DataTable(jsonPopParams);
var tblView = new google.visualization.DataView(wdt);
tblChart.draw(tblView, tabOpt);
设置断点和步进虽然每个指令填充传递到图表对象的视图,我可以看到,对于格式的值是越来越填充在JSON对象jsonPopParams。
因此,例如pmean具有'6,155,177.25'
当图表呈现的格式的值,具有逗号在格式化显示一个NaN的任何值。
I created a working pared down example in JS Fiddle here:
在那里我测试三种情形
格式化值没有逗号和2位小数
###.##
使用view.getFormattedValue
并产生6,155,177.25这当然是工作围绕格式化值有逗号和2位小数
#,###.##
使用view.getFormattedValue
并产生NaN它现在正在做的事格式化的值有逗号和2位小数,但使用
view.getValue
并产生6,155,177.255默认的低位位置必须是3 ...它的工作原理,但不符合规范。
所以我不知道,如果
1)我在做之前就要用它,现在它错了谷歌固定的根本原因,现在我的错误代码是不能工作任何更多
或
2)谷歌破了一些东西,现在我的正确的代码不再工作了。
希望第二组眼睛有新鲜的视角可以看到。
任何帮助将不胜感激。谢谢
更新后的代码示例和JSFiddle将指定给具有格式化值的正确元素'.f'。 'jsonPopParams.rows [5] .c [1] .f = dView.getFormattedValue(0,colID(dView,'pmean'));' – Threadid