var data = (['Date','first charts'],
['2013-12-17 Tue', 25],['2013-12-16 Mon', 39],
['2013-12-15 Sun', 58],['2013-12-14 Sat', 30],
['2013-12-13 Fri', 14],['2013-12-12 Thu', 69],
['2013-12-11 Wed', 5],['2013-12-10 Tue', 24],
['2013-12-09 Mon', 83],['2013-12-08 Sun', 38],
['2013-12-07 Sat', 58],['2013-12-06 Fri', 13],
['2013-12-05 Thu', 5],['2013-12-04 Wed', 24],
['2013-12-03 Tue', 44],['2013-12-02 Mon', 80],
['2013-12-01 Sun', 99],['2013-11-30 Sat', 19],
['2013-11-29 Fri', 74],['2013-11-28 Thu', 93],
['2013-11-27 Wed', 13],['2013-11-26 Tue', 4],
['2013-11-25 Mon', 7],['2013-11-24 Sun', 79],
['2013-11-23 Sat', 99],['2013-11-22 Fri', 82],
['2013-11-21 Thu', 54],['2013-11-20 Wed', 74],['2013-11-19 Tue', 93]);
var data2 = (['Date','Second charts'],['2013-12-17 Tue', 49],
['2013-12-16 Mon', 32],['2013-12-15 Sun', 88],
['2013-12-14 Sat', 43],['2013-12-13 Fri', 63],
['2013-12-12 Thu', 82],['2013-12-11 Wed', 54],
['2013-12-10 Tue', 73],['2013-12-09 Mon', 57],
['2013-12-08 Sun', 29],['2013-12-07 Sat', 32],
['2013-12-06 Fri', 4],['2013-12-05 Thu', 7],
['2013-12-04 Wed', 62],['2013-12-03 Tue', 98],
['2013-12-02 Mon', 18],['2013-12-01 Sun', 53],
['2013-11-30 Sat', 73],['2013-11-29 Fri', 93],
['2013-11-28 Thu', 48],['2013-11-27 Wed', 32],
['2013-11-26 Tue', 3],['2013-11-25 Mon', 23],
['2013-11-24 Sun', 81],['2013-11-23 Sat', 73],
['2013-11-22 Fri', 67],['2013-11-21 Thu', 42],
['2013-11-20 Wed', 62],['2013-11-19 Tue', 81]);
在google visualization api中,此数据可用作单个图表。 https://developers.google.com/chart/interactive/docs/gallery/linechart
他们是2张图表的数据。每个用于尊重单个数据。我有2个数据。两个数据都有相同的数据。我想简单地创建一个包含这些数据的数组2.我怎么做。
我目前的意思是
['2013-12-17 Tue', 25]
&安培;来自第二桌
['2013-12-17 Tue', 49]
我希望将其作为
['2013-12-17 Tue',25, 49]
我想添加第二个值。基于索引的所有日期都是相同的。我如何在Javascript中做到这一点。
答案 0 :(得分:0)
首先,我假设数组符号为
var data = [['Date','first charts'], ...
而不是
var data = (['Date','first charts'], ...
您可以将“第二个图表” - 值导入data
,如下所示:
for (var i=0;i<data2.length;i++) {
data[i].push(data2[i][1]);
}
所以data[1]
=&gt; ["2013-12-17 Tue", 25, 49]
然后像这样创建Google可视化DataTable
var dataSet = google.visualization.arrayToDataTable(data);
请参阅此工作小提琴中的上述内容 - &gt; http://jsfiddle.net/9aFTh/
答案 1 :(得分:0)
如果将这两个数据集导入DataTables,则可以使用google.visualization.data.join
函数(documentation)创建合并的DataTable:
var dataTable1, dataTable2; // the two DataTables
// full join the two DataTables on dataTable1 column 0 to dataTable2 column 0
var mergedData = google.visualization.data.join(dataTable1, dataTable2, 'full', [[0, 0]], [1], [1]);