Trouble loading histogram into html document.

15 views
Skip to first unread message

Stormin Norman

unread,
Nov 22, 2015, 11:33:16 AM11/22/15
to Google Visualization API
I am having trouble with loading a Histogram into a div on my html. My code takes some text and makes an array that contains the frequency of each letter in the text. 
This would be the array when the default text is entered. I am not sure if it is in correct format for google charts.

var frequency = { A : 25, B : 25, C : 25, D : 50, E : 100, F : 25, G : 25, H : 50, I : 25, J : 25, K : 25, L : 25, M : 25, N : 25, O : 100, P : 25, Q : 25, R : 50, S : 25, T : 50, U : 50, V : 25, W : 25, X : 25, Y : 25, Z : 25};

My code for generating the Chart is within a function. The function call occurs when a button is clicked. 




<script language = "JavaScript">
function createImageChart(){  
      

   var frequency = createfrequency();
   

   google.load('visualization', '1', {'packages':['corechart']});
   
   
   google.setOnLoadCallback(drawChart);
   
   
    function drawChart() {
   
var data = google.visualization.arrayToDataTable(frequency);
var data = new google.visualization.DataTable();
       
var options = {
          title: 'The Frequency table',
          legend: { position: 'none' },
        };
var chart = new google.visualization.Histogram(document.getElementById('chart_div'));
chart.draw(data, options);
   
        
   }
   }

</script>


When it runs I receive a blank page. I have read from online that google.load uses a document.write. 
What should change so that the chart appears in a div on the html page?
Should I display the chart by using "document.getElementById("showImage").innerHTML = chart.draw(data, options);" ?

Daniel LaLiberte

unread,
Nov 23, 2015, 12:16:24 AM11/23/15
to Google Visualization API
Hi Stormin,

Since you didn't include your createFrequency function, we can't tell whether the result is in the correct form.  What you would need, however, is an array of arrays.   The documentation page shows some examples: https://developers.google.com/chart/interactive/docs/gallery/histogram


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/e5fe630e-ba42-42bc-ae44-706a087335f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA
Reply all
Reply to author
Forward
0 new messages