Consider drawing a column chart and I don't get any data from the data source, How do we draw an empty chart instead of showing up a red colored default message saying "Table has no columns"?
Empty Rows If your form has blank rows, it may be because these rows used to have data in them but they were deleted. To truly delete rows, highlight the rows by clicking on the "2" and dragging to "5".
to make the chart look empty, use transparent as the color and add a border... colors: ['transparent'], pieSliceBorderColor: '#9e9e9e', see following working snippet...
Can I use charts offline? Your users' computers must have access to https://www.gstatic.com/charts/loader.js in order to use the interactive features of Google Charts. This is because the visualization libraries that your page requires are loaded dynamically before you use them.
What I do is initialize my chart with 1 column and 1 data point (set to 0). Then whenever data gets added I check if there is only 1 column and that it is the dummy column, then I remove it. I also hide the legend to begin so that it doesn't appear with the dummy column, then I add it when the new column gets added.
Here is some sample code you can plug in to the Google Visualization Playground that does what I am talking about. You should see the empty chart for 2 seconds, then data will get added and the columns will appear.
var data, options, chart; function drawVisualization() { data = google.visualization.arrayToDataTable([ ['Time', 'dummy'], ['', 0], ]); options = { title:"My Chart", width:600, height:400, hAxis: {title: "Time"}, legend : {position: 'none'} }; // Create and draw the visualization. chart = new google.visualization.ColumnChart(document.getElementById('visualization')); chart.draw(data,options); setTimeout('addData("12:00",10)',2000); setTimeout('addData("12:10",20)',3000); } function addData(x,y) { if(data.getColumnLabel(1) == 'dummy') { data.addColumn('number', 'Your Values', 'col_id'); data.removeColumn(1); options.legend = {position: 'right'}; } data.addRow([x,y]); chart.draw(data,options); }
A even better solution for this problem might be to use a annotation column instead of a data column as shown below. With this solution you do not need to use any setTimeout or custom function to remove or hide your column. Give it a try by pasting the given code below into Google Code Playground.
function drawVisualization() { var data = google.visualization.arrayToDataTable([ ['', { role: 'annotation' }], ['', ''] ]); var ac = new google.visualization.ColumnChart(document.getElementById('visualization')); ac.draw(data, { title : 'Just a title...', width: 600, height: 400 }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With