给定轴上的所有系列必须具有相同的数据类型.google chart api error

时间:2016-04-07 17:03:44

标签: javascript json dom javascript-objects google-chartwrapper

我正在使用谷歌图表api,其中我从json获取值。我正在与json在这里分享我的javascript.its给我错误,它必须是相同的数据类型,但据我所知,它是相同的类型。

function drawChart2() {

  var jsa = [
    {
        "date": "01-APR-16",
        "creditCardCount": 3,
        "invoiceCount": 1
    },
    {
        "date": "06-APR-16",
        "creditCardCount": 2,
        "invoiceCount": 3
    },
    {
        "date": "29-MAR-16",
        "creditCardCount": 3,
        "invoiceCount": 1
    },
    {
        "date": "30-MAR-16",
        "creditCardCount": 4,
        "invoiceCount": 3
    },
    {
        "date": "31-MAR-16",
        "creditCardCount": 1,
        "invoiceCount": 1
    }
]


var outputArrayForInvoiceAndCredit = new Array();
// header
var headerArray1 = ['Day', 'CreditCard', 'Invoice'];
outputArrayForInvoiceAndCredit.push(headerArray1);
for (var i = 0; i < jsa.length; i++){
    var obj1 = jsa[i];
    var innerArray = new Array();
    innerArray[0] = obj1.date;
    innerArray[1] = obj1.creditCardCount;
    innerArray[2] = obj1.InvoiceCount;
    outputArrayForInvoiceAndCredit.push(innerArray);
}

  var data2 = google.visualization.arrayToDataTable(outputArrayForInvoiceAndCredit);

  var options2 = {
    title: 'CreaditCard/Invoice Details',
    curveType: 'function',
    legend: {
      position: 'bottom'
    }
  };

  var chart2 = new google.visualization.LineChart(document.getElementById('cc/invoice'));

  chart2.draw(data2, options2);
}

同时如果我在没有json的情况下使用它,它工作正常 下面是可以正常使用的脚本

  function drawChart3() {
  var data3 = google.visualization.arrayToDataTable([
    ['Day', 'Sales','exp'],
    ['4-APRIL-16', 1000,200],
    ['5-APRIL-16', 1170,300],
    ['6-APRIL-16', 660,400],
    ['7-APRIL-16', 1030,500]
  ]);

  var options3 = {
    title: 'Company Performance',
    curveType: 'function',
    legend: {
      position: 'bottom'
    }
  };

  var chart3 = new google.visualization.LineChart(document.getElementById('curve_chart'));

  chart3.draw(data3, options3);
}

任何人都可以帮我解决这个问题。谢谢你

0 个答案:

没有答案