Google Chart API error “All series on a given axis must be of the same data type”

前端 未结 4 419
野性不改
野性不改 2020-12-09 15:06

\"enter

I have LineGraph using googlechart. This graph is created with the following c

相关标签:
4条回答
  • 2020-12-09 15:46

    I think specifying the type in header row will fix the issue.

    var data = google.visualization.arrayToDataTable([
    ['Category', {label: 'Return', type: 'number'}, {label: 'Risk', type: `enter code here`'number'}],
    [1.5,  20, 50]
    ]);
    
    0 讨论(0)
  • 2020-12-09 15:57

    For me this error was caused by having an additional column which never had any values appended to it

    0 讨论(0)
  • 2020-12-09 15:59

    Finally, I have got a solution to my problem. I hope this will help many others like me. The problem is basically a limitation of arrayToDataTable method. The row of data must have the correct type in all columns. Since we have null values in rows, the API is either assuming that the data type of that column in null or it is throwing an error about not getting a valid data type. To fix this, you will have to switch to the a standard DataTable constructor

    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Year');
    data.addColumn('number', 'Health (P)');
    data.addColumn('number', 'Health (A)');
    data.addColumn('number', 'Gender (P)');
    data.addColumn('number', 'Gender (A)');
    data.addColumn('number', 'Education (P)');
    data.addColumn('number', 'Education (A)');
    data.addColumn('number', 'Agriculture (P)');
    data.addColumn('number', 'Agriculture (A)');
    data.addColumn('number', 'Social protection (P)');
    data.addColumn('number', 'Social protection (A)');
    data.addColumn('number', 'Environment (P)');
    data.addColumn('number', 'Environment (A)');
    data.addColumn('number', 'Water/sanitation (P)');
    data.addColumn('number', 'Water/sanitation (A)');
    data.addRows([
    
        ['2008',81.06,null,1.32,null,94.68,0,13.41,null,30.36,null,19.78,null,36.87,null],
        ['2009',27.13,null,22.34,null,33.6,null,79.92,null,1.34,null,89.77,0,15.68,null],
        ['2010',104.89,0,14.61,null,33.46,null,30.29,null,22.28,null,107.81,null,1.39,null],
        ['2011',55,0,110.69,null,1.3,null,106.24,0,14.45,null,27.34,null,30.71,null],
        ['2012',29.96,null,27.88,null,44.77,null,133.83,null,1.31,null,105.01,null,17.83,null],
        ['2013',0,null,0,null,0,null,0,null,0,null,0,null,0,null]
    ]);
    

    Copied from the following link https://groups.google.com/forum/?fromgroups=#!topic/google-visualization-api/2Jafk8PyjV4

    Alternatively, with arrayToDataTable() you can specify the type in the header row. See the docs for more https://developers.google.com/chart/interactive/docs/datatables_dataviews#arraytodatatable

    var data = google.visualization.arrayToDataTable([
          ['Categegories', {label: 'R1', type: 'number'} , {label: 'R2', type: 'number'} , {label: 'R3', type: 'number'} , {label: 'R4', type: 'number'} , {label: 'R5', type: 'number'} , {label: 'R6', type: 'number'} ],
    
          ['A',          1,     4,       2,    4,       1,  null],
    
          ['D',          3,  null,    null,    7,    null,     1],
    
          ['G',          null,  null,    null,       8,    null,  null],
    
        ]);
    
    0 讨论(0)
  • 2020-12-09 15:59

    I got this error by creating a bar chart that had two columns with strings and one with numbers. I was intending to display a view that kept the second string column hidden but forgot.

    0 讨论(0)
提交回复
热议问题