Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove default error message in google chart

How to remove default error shown in google chart, which looks like so:

enter image description here

like image 553
user5815554 Avatar asked Jan 20 '16 11:01

user5815554


1 Answers

To remove google errors, listen for the 'error' event on the chart or other object.
When the event is fired, use google.visualization.errors.removeError

Here, I intentionally cause an error, remove it from the google chart, and display it in my own div

google.load('visualization', '1', {packages:['corechart'], callback: drawChart});

function drawChart() {
  var data = google.visualization.arrayToDataTable([
    ["Element", "Density", { role: "style" } ]
  ]);

  var view = new google.visualization.DataView(data);
  view.setColumns([0, 1,
                   { calc: "stringify",
                     sourceColumn: 1,
                     type: "string",
                     role: "annotation" },
                   2]);

  var chart = new google.visualization.ColumnChart(document.getElementById("chart_div"));

  google.visualization.events.addListener(chart, 'error', function (googleError) {
      google.visualization.errors.removeError(googleError.id);
      document.getElementById("error_msg").innerHTML = "Message removed = '" + googleError.message + "'";
  });

  chart.draw(view, {height: 20});
}
<script src="https://www.google.com/jsapi"></script>
<div id="chart_div"></div>
<div id="error_msg"></div>
like image 184
WhiteHat Avatar answered Oct 25 '22 19:10

WhiteHat