多维数组 - google.visualization.arrayToDataTable

时间:2016-09-06 12:25:59

标签: javascript arrays charts google-visualization

我无法将多维数组传递给protected void showRouteValues(object sender, EventArgs e) { var context = HttpContext.Current; if (context == null) return; var routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(context)); }
绘制谷歌图表。

My Array如下,c(1-5)和a(1-5)是整数。

google.visualization.arrayToDataTable

数据确实可以通过,但是当我使用它来绘制图表时,它会给我一个错误:
"给定轴上的所有系列必须具有相同的数据类型"。

我正在使用图表:

MultiArray = new Array(6);
MultiArray [0] = new Array(3);
MultiArray [0][0] = 'SLA';
MultiArray [0][1] = 'CV';
MultiArray [0][2] = 'AV';
MultiArray [1] = new Array(3);
MultiArray [1][0] = 'Long List Candidates';
MultiArray [1][1] = c1;
MultiArray [1][2] = a1;
MultiArray [2] = new Array(3);
MultiArray [2][0] = 'Call-in/Book-in Candidate';
MultiArray [2][1] = c2;
MultiArray [2][2] = a2;
MultiArray [3] = new Array(3);
MultiArray [3][0] = 'Interview Candidate';
MultiArray [3][1] = c3;
MultiArray [3][2] = a3;
MultiArray [4] = new Array(3);
MultiArray [4][0] = 'Candidate Reference Call';
MultiArray [4][1] = c4;
MultiArray [4][2] = a4;
MultiArray [5] = new Array(3);
MultiArray [5][0] = 'Shortlist Candidate';
MultiArray [5][1] = c5;
MultiArray [5][2] = a5;

var data = new google.visualization.arrayToDataTable(MultiArray);

我试图将所有值更改为Integers,但之后它拒绝超越var chart7 = new google.visualization.ColumnChart(document.getElementById('c7')); 函数。

1 个答案:

答案 0 :(得分:0)

似乎在这里工作正常......

你确定c(1-5)和a(1-5)是整数吗?

如果有任何字符串,只是遗漏或超出范围,图表将抛出错误

请参阅以下工作代码段...

google.charts.load('current', {packages:['corechart', 'table']});
google.charts.setOnLoadCallback(drawChart);

function drawChart() {
  var c1 =  1;
  var a1 =  2;
  var c2 =  3;
  var a2 =  4;
  var c3 =  5;
  var a3 =  6;
  var c4 =  7;
  var a4 =  8;
  var c5 =  9;
  var a5 = 10;

  var MultiArray = new Array(6);
  MultiArray [0] = new Array(3);
  MultiArray [0][0] = 'SLA';
  MultiArray [0][1] = 'CV';
  MultiArray [0][2] = 'AV';
  MultiArray [1] = new Array(3);
  MultiArray [1][0] = 'Long List Candidates';
  MultiArray [1][1] = c1;
  MultiArray [1][2] = a1;
  MultiArray [2] = new Array(3);
  MultiArray [2][0] = 'Call-in/Book-in Candidate';
  MultiArray [2][1] = c2;
  MultiArray [2][2] = a2;
  MultiArray [3] = new Array(3);
  MultiArray [3][0] = 'Interview Candidate';
  MultiArray [3][1] = c3;
  MultiArray [3][2] = a3;
  MultiArray [4] = new Array(3);
  MultiArray [4][0] = 'Candidate Reference Call';
  MultiArray [4][1] = c4;
  MultiArray [4][2] = a4;
  MultiArray [5] = new Array(3);
  MultiArray [5][0] = 'Shortlist Candidate';
  MultiArray [5][1] = c5;
  MultiArray [5][2] = a5;

  var data = new google.visualization.arrayToDataTable(MultiArray);

  var chartCol = new google.visualization.ColumnChart(document.getElementById('chart_div_col'));
  chartCol.draw(data);

  var chartTable = new google.visualization.Table(document.getElementById('chart_div_table'));
  chartTable.draw(data);
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div_col"></div>
<div id="chart_div_table"></div>