asp.net Google图表json回调未显示图表

时间:2018-11-04 08:48:11

标签: c# asp.net ajax charts

我从ajax调用中获取了json数据,将其显示在代码标签中,但是当我制作

var data = new google.visualization.arrayToDataTable(response, false);

调用失败(没有图形显示,没有错误消息)。另外,如果我手动将返回的数据和硬代码复制到“ arrayToDataTable”方法中,则一切正常(即

var data = new google.visualization.arrayToDataTable([['Month', '2013', '2014', '2015', '2016'], ...., false);

function GetChartData() {
  alert("GetChartData()");
  var url = '@Url.Action("GetChartData", "Graphing")';
  var stockitems = $('#SelectedStockItemID'); // cache it
  var stockGroups = $('#SelectedStockGroupID'); // cache it
  var customers = $('#SelectedCustomerID'); // cache it
  // public JsonResult GetChartData(int ? customerID, int ? stockItemID, int ? stockGroupID)
  $.getJSON(url, {
    StockGroupID: stockGroups.val(),
    stockItemID: stockitems.val(),
    customerID: customers.val()
  },
  function(response) {
    alert("call back from getJSON()");
    $("#codeDisplay").text(response);
    // Load google charts
    var data = new google.visualization.arrayToDataTable(response, false);
    alert("after arraytoDataTable");
    // Optional; add a title and set the width and height of the chart
    var options = {
      'width': 1000,
      'height': 600
    };
    // Display the chart inside the <div> element with id="piechart"
    var chart = new google.visualization.LineChart(document.getElementById('SalesChart'));
    chart.draw(data, options);
  });
}

0 个答案:

没有答案