2012-11-04 12 views
20

enter image description herebłąd Google Chart API „Wszystkie serie na danej osi muszą być tego samego typu danych”

Mam graf krawędziowy wykorzystaniem googlechart. Ten wykres jest tworzony z następującego kodu

function drawChart() { 
    var data = google.visualization.arrayToDataTable([ 

     ['Categegories', 'R1' , 'R2' , 'R3' , 'R4' , 'R5' , 'R6' ], 

     ['A',   1,  4,  2, 4,  1, null], 

     ['D',   3, null, null, 7, null,  1], 

     ['G',   null, null, null,  8, null, null], 

    ]); 

    var options = { 
     title: 'Graph', 
     pointSize: 6, 
     vAxis: {minValue:0, maxValue:10,gridlines:{count:6}}, 
    }; 

    var chart = new google.visualization.LineChart(document.getElementById('chart_div')); 
    chart.draw(data, options); 
    } 

Nieoczekiwanie Jeśli usunąć wiersz danych ['D', 3, null, null, 7, null, 1],

Produkuje błąd mówiąc, że All series on a given axis must be of the same data type


mam zmniejszyć mojego kodu tylko jedna linia i stwierdziłem, że jest problem z wartościami null

np.

['Category', 'R1' , 'R2' , 'R3' ], 
['A',  2, 1, 1] 

generuje wykres natomiast jeśli dodam null wartość w każdym miejscu w danych czyli w miejscu (2,1,1) nie ..

Czekam na jakiś wskazówek ekspertów na temat ustawiania jakąś opcję do obsługi wartości null ... To bardzo dziwne, że niektóre wartości zerowe działają, a czasem nie .. :(

+0

Jest jeszcze jedna opcja 'interpolateNulls: 'true'' \t ale to działa na pakiet' pakietów: [' Linechart '] ':(i muszę pracować dla pakietu' pakietów: [ "corechart"] ' – Shahid

Odpowiedz

38

Wreszcie mam rozwiązanie mojego problemu. Mam nadzieję, że to pomoże wielu innym Problem polega zasadniczo na ograniczeniu metody arrayToDataTable. Wiersz danych musi mieć poprawny typ wszystkie kolumny. Ponieważ mamy wartości null w wierszach, interfejs API zakłada, że ​​typ danych tej kolumny ma wartość null, lub generuje błąd polegający na nieprzyjęciu prawidłowego typu danych. Aby rozwiązać ten problem, trzeba będzie przełączyć do standardowego DataTable konstruktora

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] 
]); 

kopiowane z następującym linkiem https://groups.google.com/forum/?fromgroups=#!topic/google-visualization-api/2Jafk8PyjV4

Alternatywnie, z arrayToDataTable() można określić typ w wierszu nagłówka. Zobacz docs o więcej 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], 

    ]); 
1

mam ten błąd tworząc wykres słupkowy, który miał dwie kolumny z ciągów i jeden z numerów. Miałem zamiar wyświetlić widok, który ukrył drugą kolumnę z napisami, ale zapomniał.

3

Dla mnie ten błąd został spowodowany przez posiadające dodatkową kolumnę, która nigdy nie miałem żadnych wartości dołączane do niego

3

myślę określający typ w wierszu nagłówka będzie rozwiązać problem.

var data = google.visualization.arrayToDataTable([ 
['Category', {label: 'Return', type: 'number'}, {label: 'Risk', type: `enter code here`'number'}], 
[1.5, 20, 50] 
]); 
Powiązane problemy