EliteTech
EliteTech

Reputation: 386

Unknown Header Type

For some reason Google Visualization API stopped working for me since last night. I keep getting an Unknown Header Type error in the javascript console which doesn't seem to be very common. I have not found a single reference to this error in relation to the google charts api.

Here is the code I use to generate my datatable

var gData = new google.visualization.DataTable();
                gData.addColumn("string", "Interval");
                var mtw=false;
                var maxColumns=0;
                $.each(data, function(key, val){
                    if(j==0){
                         $.each(val, function(key2, val2){
                            j++;
                            gData.addColumn("number", key2);
                            if(key2.length==3 || key2.length==4){
                                mtw=true;
                            }
                        });
                    }

                    var row = new Array();
                    var k=0;
                    row[k] = key;
                    $.each(val, function(key3, val3){
                        k++;
                        row[k] = parseInt(val3);
                        if(maxColumns < k){
                            maxColumns = k;
                        }
                    });
                    while(maxColumns > k){
                        k++;
                        row[k]=0;
                    }
                    rows[i] = row;
                    i++;
                });

                gData.addRows(rows);

I have been loggin the gData object and this is the column headers

    Ve: Array[6]
    0: Object
        id: ""
        label: "Interval"
        pattern: ""
        type: "string"
        __proto__: Object
    1: Object
        id: ""
        label: "11/18/2013"
        pattern: ""
        type: "number"
        __proto__: Object
    2: Object
        id: ""
        label: "11/19/2013"
        pattern: ""
        type: "number"
        __proto__: Object
    3: Object
        id: ""
        label: "11/20/2013"
        pattern: ""
        type: "number"
        __proto__: Object
    4: Object
        id: ""
        label: "11/21/2013"
        pattern: ""
        type: "number"
        __proto__: Object
    5: Object
        id: ""
        label: "11/22/2013"
        pattern: ""
        type: "number"
        __proto__: Object
    length: 6
    __proto__: Array[0]

I am not sure why this stopped working all of a sudden.

Upvotes: 1

Views: 6827

Answers (1)

Milche Patern
Milche Patern

Reputation: 20482

addColumn(type, opt_label, opt_id)

where opt_label is a string.

  • type - A string with the data type of the values of the column. The type can be one of the following: 'string' 'number' 'boolean' 'date' 'datetime' 'timeofday'.
  • opt_label - [Optional] A string with the label of the column. The column label is typically displayed as part of the visualization, for example as a column header in a table, or as a legend label in a pie chart. If not value is specified, an empty string is assigned.
  • opt_id - [Optional] A string with a unique identifier for the column. If not value is specified, an empty string is assigned.

Maybe key2 needs to be a 'string' gData.addColumn("number", key2);

Also, i can't see where val2 and key2 are defined.

So my 'best-guess' answer is : look into your json object and notice you sledgehammered it .

Upvotes: 2

Related Questions